我们都知道Nginx是可以做反向代理的,就像Apache的ProxyPassReverse一样。
在apache中配置反向代理,我们这样写:
<VirtualHost myhost:80> ServerName myhost DocumentRoot /path/to/myapp/public ProxyPass / http://myapp:8080/ ProxyPassReverse / http://myapp:8080/ </VirtualHost>
但是Nginx没有ProxyPassReverse,解决办法就是添加丢失的HTTP头:
server { listen myhost:80; server_name myhost; location / { root /path/to/myapp/public; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://myapp:8080; } }
那些丢失的头信息都是什么呢?
X-Forwarded-For:客户端IP地址 X-Forwarded-Host:客户端发起的原始主机请求头信息 X-Forwarded-Server:代理服务器主机名
暂无评论