Apache rewrite rules behind a nginx proxy
- by Tuinslak
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