【问题标题】:how to set the locaction in nginx.conf for removing URL's trailing slash?如何在 nginx.conf 中设置位置以删除 URL 尾部斜杠?
【发布时间】:2019-06-01 07:18:44
【问题描述】:

今天用了两台服务器做nginx,nginx.conf的内容如下:

#192.168.2.98
server {
    listen 8091;
    location ^~ /ttank {
        alias /develop/servers-running/front/vue-public/dist;
        index index.html;
        try_files $uri $uri/ /ttank/index.html;
     }
 }



#192.168.2.97
location /ttank {
   proxy_pass http://192.168.2.98:8091;
   proxy_set_header Host $host;
   proxy_set_header  X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_redirect off;
}

我可以通过在chrome中输入地址:http://192.168.2.98:8091/ttank访问192.168.2.98:8091/ttank,我也可以访问192.168.2.98 em> 的 ttank 通过输入地址 http://192.168.2.97/ttank/,但是当我将地址 http://192.168.2.97/ttank/ 更改为 http://192.168.2.97/ttank 时,我的 chrome永远进入等待状态,两个地址唯一的区别就是最后一个“/”,ttank访问ttank时不知道怎么修改配置文件去掉最后一个“/” >192.168.2.97?

【问题讨论】:

    标签: nginx vue.js nginx-location nginx-reverse-proxy


    【解决方案1】:

    尝试使用重写规则来去掉结尾的斜线

    location /ttank {
        rewrite ^/(.*)/$ /$1 break;
        ...;
        ...;
        proxy_pass ...;
    }
    

    应该这样做

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 2016-01-10
      • 1970-01-01
      相关资源
      最近更新 更多