我有以下configuration:
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name _; location / { index index.html; } server_name command_asdf location /asdf/ { proxy_pass http://127.0.0.1:3001/; }
当我去http://server/asdf/index.html一切工作正常。
但是,如果我转到http:// server / asdf /或http:// server / asdf,那么它们都会将我redirect到http://server/index.html而不是http://server/asdf/index.html
我花了好几个小时试图弄清楚如何让它redirect到子目录上的索引页面,但可悲的是没有成功。
我有一些服务器,我需要使用proxy_pass上,但是上面是最简单的configuration,我可以显示。
谢谢!
几周后..已经设法解决我的问题。 解决scheme是:
proxy_redirect / $request_uri;
所以当用户访问foo.com/bar/时,它会redirect到foo.com/index.html
这发生在proxy_pass服务器发出的302redirect中。
添加到我的configuration上面的行将redirectfoo.com/bar/到http://foo.com/bar/然后加载index.html页面。
完整configuration:
server_name bar; location /bar/ { proxy_pass http://127.0.0.1:3001/; proxy_redirect / $request_uri; }
作为参考,$ request_uri等于位置和子目录,即foo.com/bar/