我正在Apache Web服务器(:8080)之前运行nginx(:80)
Nginxconfiguration(snippet):
location / { proxy_pass http://www.domain.tld:8080; proxy_set_header X-Real-IP $remote_addr;
如果我设置本地主机,而不是www.domain.tld,我的浏览器被redirect到http:// localhost:8080 。
Apache重写规则:
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]
到现在为止还挺好。
但是,每个链接(使用相对path)都显示为http://www.domain.tld:8080 / page,而不是停留在端口80上。
有没有办法通过重写规则来解决这个问题? 我不想使用绝对path。
谢谢
解决这个添加到nginxconfiguration:
proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;