plko345
V2EX  ›  NGINX

请教 nginx 的 rewrite 配置问题

By plko345 at 2021 年 3 月 1 日 · 2553 次点击

我希望 ex.com/abc 能自动在末尾加上 ex.com/abc/, /abc/ 有斜杠的会代理到后端

我用的是 openresty, 理论上和 nginx 没什么差别

# 一
location / {
    ...
    proxy_pass ex2.com;
}

# 二
location /abc {
    rewrite ^/(abc)$ $1/ permanent;
}

# 三
location /abc/ {
    ...
    proxy_pass ex2.com;
}

现在问题是, 一个 nginx 成功, 另一个 nginx 失败, 配置除了域名都是一样的, 搞了一晚上了

有大佬有遇到过吗? 或者给个解题思路, 或者有没有其它方案, 先放过了

1 条回复
cdlixucd
   1
cdlixucd  
   2021 年 3 月 2 日
有斜杠和没斜杠完全是两个效果 去 nignx 官网搜下 之前一个朋友也是搞了很久
› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
© 2026 V2EX · 34ms · 3.9.8.5