Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
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
    
Will do (You can accept your own answer in 39 minutes) –  Tuinslak Jan 14 '11 at 16:55
add comment

1 Answer

up vote 0 down vote accepted

Solved by adding this to the nginx config:

proxy_set_header Host $host; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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