Apache rewrite rules behind a nginx proxy
Posted
by
Tuinslak
on Server Fault
See other posts from Server Fault
or by Tuinslak
Published on 2011-01-12T17:34:42Z
Indexed on
2011/01/12
17:55 UTC
Read the original article
Hit count: 212
Hi,
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 redirect 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
© Server Fault or respective owner