Nginx:正确设置 proxy_path。网址问题
我有几台服务器在虚拟机中运行。我有一个运行 nginx 来代理对这些服务器的请求。例如, http://mydomain.com/wiki 应该将请求代理到 http://192.168.122.3。 192.168.122.3 运行 apache,DocumentRoot = /var/www/wiki。一切正常,但是当页面加载时,所有路径都指向 / 而不是 /wiki (例如
)。这对于 apache 来说似乎没问题,但对于浏览器则不然——它无法加载图像等。 将 apache 中的 DocumentRoot 更改为 /var/www 并从 nginx 传递 /wiki 没有帮助 - mediawiki 开始重定向到 /wiki,nginx 将其重定向回 apache 等等,然后再说明循环重定向。 在 VM 中运行的其他项目(例如 Redmine(Ruby on Rails))的行为相同。,而不是 /wiki/bla-bla- bla"
有什么办法可以解决这个问题吗?是否有正确的方法将 /subdir 等 URL 代理到其他服务器?
这是 nginx 服务器部分:
server {
listen 192.168.122.7:80;
server_name mydomain.com;
access_log /var/log/nginx/localhost.access.log;
location / {
}
location /wiki/ {
proxy_pass http://192.168.122.3/;
}
}
I have several servers running in virtual machines. And I have one running nginx for proxying requests to those servers. For example, http://mydomain.com/wiki should proxy request to http://192.168.122.3. 192.168.122.3 runs apache with DocumentRoot = /var/www/wiki. Everything works fine, but when page loads, all the paths there point to / instead of /wiki (like <img src="/bla-bla-bla"/>, not /wiki/bla-bla-bla"
). It seems to be ok for apache, but not for browser - it can't load images etc.
Changing DocumentRoot in apache to /var/www and passing /wiki from nginx doesn't help - mediawiki starts redirection to /wiki, nginx redirects it back to apache and so on before it says about looped redirections.
The other projects runing in VMs like Redmine (ruby on rails) act the same.
Is there any way to solve this problem? Is there proper way to proxy URLs like /subdir to other servers?
This is nginx server section:
server {
listen 192.168.122.7:80;
server_name mydomain.com;
access_log /var/log/nginx/localhost.access.log;
location / {
}
location /wiki/ {
proxy_pass http://192.168.122.3/;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 proxy_redirect 指令。
Your should use proxy_redirect directive.