eli*_*ocs 4 nginx proxy reverse-proxy
我已经设置了一个 Web 服务器来在http://localhost:3000上查看我的存储库(一个 Gitalist 实例),我想使用 nginx 设置一个代理。
我希望在接收到 DOMAIN/git/ 之类的 URI 时将请求代理到我的存储库视图。
我当前的 nginx 配置声明如下:
location /git {
proxy_pass http://localhost:3000/;
}
Run Code Online (Sandbox Code Playgroud)
请求确实被代理到服务器,但没有任何图像/链接或 css 可以解析,因为它们指向“ http://localhost:3000/logo.png ”例如。
编辑
如果我 proxy_pass 到实际服务器地址,它确实有效:
location /git {
proxy_pass http://192.168.1.111:3000/;
}
Run Code Online (Sandbox Code Playgroud)
但是应该有一种在代理时隐藏实际服务器地址的方法。
小智 6
尝试 nginx wiki 中提供的解决方案:
http://wiki.nginx.org/LikeApache
结果,应该是这样的。
location /git {
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://192.168.1.111:3000/;
}
Run Code Online (Sandbox Code Playgroud)
在 URI 是绝对的情况下,解决方案可以是使用 Nginx HTTPSubModule或切换到 Apache 及其mod_proxy_html模块。他们都能够修改从后端服务器收到的响应并进行一些替换。