我在配置 Nginx 以重写对特定端点的所有请求时遇到一些麻烦。
我有一个 Nodejs 应用程序在端口 8080 上运行,我想要所有 http://SERVER_IP/ * 请求显示http://127.0.0.1:8080/statuscheck
我尝试过(在/etc/nginx/sites-available/default 文件中):
location / {
rewrite ^.*$ /statuscheck last;
proxy_pass http://127.0.0.1:8080;
}
但是我得到了 500。错误日志显示:
[error] 25756#0: *115803 rewrite or internal redirection cycle while processing "/statuscheck"
感谢您的帮助。
最佳答案
rewrite
指令中的正则表达式也与 /statuscheck
匹配,因此任何导致表达式被多次求值的重写或重定向都会导致循环。其中包括标志参数:last
、redirect
和 permanent
。
但是,break
标志参数会停止处理 rewrite
指令并继续处理当前位置内的 URL。例如:
location / {
rewrite ^ /statuscheck break;
proxy_pass http://127.0.0.1:8080;
}
参见this document了解详情。
关于node.js - Nginx - 将所有内容重定向到特定端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38420255/