nginx 转发空路径

原创
2022/12/05 22:25
阅读数 66

配置了 nginx

server {
    listen 80;

    server_name test.abc.com;

    location /app {
    	rewrite /app(.*) $1 break;
    	proxy_pass http://123456.gradio.app;
    	proxy_set_header Host "123456.gradio.app";
    }

    location / {
        return 200 "ok";
    }
}

访问 http://test.abc.com/app 出现下面的错误

2022/12/05 22:02:18 [error] 17130#0: *5 the rewritten URI has a zero length, 
client: 127.0.0.1, 
server: test.abc.com, 
request: "GET /app HTTP/1.1", 
host: "test.abc.com"

原因:转发时,请求空路径到 proxy,解决方案:

server {
    listen 80;

    server_name test.abc.com;

    location /app/ {
    	rewrite /app(.*) $1 break;
    	proxy_pass http://123456.gradio.app;
    	proxy_set_header Host "123456.gradio.app";
    }

    location / {
        return 200 "ok";
    }
}

把 location /app 改成了 location /app/

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部