Nginx代理ttyd服务报错:'proxy_pass' cannot have URI part解决方案

在使用Nginx代理ttyd服务时,如果配置文件中location指令使用了正则表达式,并将URI部分添加到proxy_pass指令中,就会出现'proxy_pass' cannot have URI part in location given by regular expression错误。

例如,以下配置就会出现该错误:nginxlocation ~ ^/ugreen/v1/ttyd { proxy_pass http://localhost:7681/; # ...其他配置}

错误原因:location指令使用正则表达式匹配URI时,proxy_pass指令不能包含URI部分。

解决方法:proxy_pass指令中的URI部分去掉。

示例: 假设需要将请求转发到http://192.168.44.229:7681/,正确的配置如下:nginxlocation ~ ^/ugreen/v1/ttyd { proxy_pass http://192.168.44.229:7681; # 去掉URI部分 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; 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_read_timeout 86400; proxy_redirect off;}

经过以上修改,Nginx就能正确代理ttyd服务,并将请求转发到指定的IP地址和端口。

Nginx代理ttyd服务报错'proxy_pass' cannot have URI part解决方案

原文地址: https://www.cveoy.top/t/topic/fNId 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录