您好:
我现在在两台机器上装了owncloud
服务,并且都已经可以正常运行,访问地址分别为:
192.168.0.21:8080/owncloud
192.168.0.22:8080/owncloud
然后修改nginx
配置,sudo vim /etc/nginx/sites-enabled/owncloud
upstream owncloud_upstream {
server 192.168.0.21:8080;
server 192.168.0.22:8080;
}
server {
listen 90;
server_name owncloud_server;
location /owncloud {
proxy_pass http://owncloud_upstream/owncloud;
}
}
# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# sudo nginx -s reload
然后访问http://192.168.0.21:90/owncloud
地址栏变成了http://test_upstream:8080/owncloud/
这个问题的原因是:
后端返回了跳转代码,但跳转 location 带有 URL 和端口,所以就跳转到了后端的 IP 和端口。
通常这是后端代码的问题,一般建议后端采用相同的域名和端口,这样不会产生跳转的问题。
如果无法采用相同的域名和端口,那可以在前端的 nginx 用 proxy_redirect 指令来替换 30x 跳转里的 location,具体参考官方文档:
https://nginx.org/r/proxy_red...