1

I am running nginx (:80) in front of an Apache webserver (:8080)

Nginx config (snippet):

location / {
    proxy_pass        http://www.domain.tld:8080;
    proxy_set_header  X-Real-IP  $remote_addr;

If I set localhost instead of www.domain.tld, my browser gets redirected to http://localhost:8080.

Apache rewrite rules:

RewriteEngine On
Options +FollowSymlinks
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) http://%{HTTP_HOST}/$1/ [L,R=301]

RewriteCond %{REQUEST_URI} !v2/
RewriteRule ^(.*)$ v1/$1 [L]

So far, so good.

However, every link (which uses relative paths) appears as http://www.domain.tld:8080/page instead of staying on port 80.

Is there any way to solve this through the rewrite rules? I don't want to use absolute paths.

Thanks

  • Solved by adding this to the nginx config: (1) proxy_set_header Host $host; (2) proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; – Tuinslak Jan 12 '11 at 22:07
  • You can also write an answer yourself and accept it, that way this question won't look like it is "unanswered". – Jan Fabry Jan 13 '11 at 9:30
  • In fact @Tuinslak you should answer your own question, remove the "** Solved **" from the question itself, and accept your own answer. – Josh Jan 14 '11 at 13:16
0

Solved by adding this to the nginx config:

proxy_set_header Host $host; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.