我在Nginx反向代理后面有一个Apache Web服务器设置,处理SSL&子域。
它几乎适用于所有内容,除非我忘记了网址的最后/结尾(例如https://vps.com/url
没有/在最后),Apache会将我重定向到本地端口(Apache只监听127.0.0.1,端口4000,如果我忘记/,它会将我重定向到https://vps.com:4000/url/
,这显然不起作用。)
这是我的nginx配置:
server {
listen 443 ssl;
// SSL Certificate location & such
access_log /var/log/nginx/apache-ssl-access.log;
error_log /var/log/nginx/apache-ssl-error.log;
server_name <my remote url>;
location ~ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:4000;
}
location ~ /\.ht {
deny all;
}
}
这是处理服务的apache配置文件:
<VirtualHost 127.0.0.1:4000>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
LogLevel warn ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我的服务器是在Debian8机器上安装的,运行这些版本:
Apache/2.4.10
nginx/1.10.2
我不知道什么是重定向或我如何防止这种想法?
答案 0 :(得分:1)
看起来Apache正在发出一个3xx响应,将一个尾部斜杠附加到以目录名结尾的URI。
间接解决方案是使用proxy_redirect
中的nginx
指令将重定向从内部地址转换为外部地址。
只需将location
块更改为前缀位置(请参阅this document)并在/
语句中附加proxy_pass
即可,因为默认操作可能已足够解决问题:
location / {
...
proxy_pass http://127.0.0.1:4000/;
}
如果需要更具体的解决方案,可以将多个proxy_redirect
语句添加到location
块。
要找到所需的确切映射,您应该使用curl
(或合适的浏览器工具)来分析HTTP 3xx响应中的Location
标头,该标头将URL设置为内部地址。
有关详情,请参阅this document。