目标是让PHP了解正确的面向web的server_port.
设置是:
端口443上的Nginx反向代理端口80上的varnish反向代理端口8008上的Nginx并运行PHP-fpm作为fastcgi.
命中80或443都工作正常,但PHP中的$_SERVER [‘SERVER_PORT’]默认情况下总是显示8008.我可以硬编码fastcgi_param server_port但是它只对80或443正确,但不是两者都正确.
# default
fastcgi_param SERVER_PORT $server_port;
# harcode to 80
fastcgi_param SERVER_PORT 80;
如何才能获得适用于PHP的面向外部的服务器端口?
最佳答案
找到了我自己的答案
原文链接:https://www.f2er.com/nginx/435697.html在SSL Nginx中,这……
proxy_set_header X-Forwarded-Proto https;
然后在清漆中,这……
sub vcl_recv {
if (req.http.X-Forwarded-Proto == "https" ) {
set req.http.X-Forwarded-Port = "443";
} else {
set req.http.X-Forwarded-Port = "80";
set req.http.X-Forwarded-Proto = "http";
}
}
然后在最后的Nginx中,这……
fastcgi_param SERVER_PORT $http_x_forwarded_port;