加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Nginx将proxy_pass服务器重定向到http://server/index.html

发布时间:2020-12-13 21:11:24 所属栏目:Nginx 来源:网络整理
导读:我有以下配置: 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 ind

我有以下配置:

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,他们都会将我重定向到http://server/index.html而不是http://server/asdf/index.html

我花了好几个小时试图找出如何让它重定向到子目录上的索引页面,但遗憾的是没有成功.

我有许多服务器需要使用proxy_pass,但上面是我可以显示的最简单的配置.

谢谢!

几周后……我设法解决了我的问题.解决方案是:

   proxy_redirect    / $request_uri;

因此,当用户访问foo.com/bar/时,它会重定向到foo.com/index.html

这发生在proxy_pass服务器发出的302重定向中.

添加到我的配置中的上述行会将foo.com/bar/正确地重定向到http://foo.com/bar/,然后加载index.html页面.

完整配置:

    server_name bar;
    location  /bar/ {
    proxy_pass http://127.0.0.1:3001/;
    proxy_redirect    / $request_uri;
    }

作为参考,$request_uri等于位置和子目录,即foo.com/bar/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读