And*_*rea 1 configuration system nginx
我有以下 nginx 配置:
server {
listen 80;
server_name default;
location / {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080/;
}
}
Run Code Online (Sandbox Code Playgroud)
当http://127.0.0.1:8080/nginx的内部服务没有响应时,返回502 Bad Gatway 错误。
我的问题:如何配置 nginx 以返回静态 html 文件,例如/var/www/error.html,发生此类错误时?
我试过的
server {
listen 80;
server_name default;
location / {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080/;
}
error_page 404 502 /error.html;
location = /error.html {
internal;
root /var/www;
}
}
Run Code Online (Sandbox Code Playgroud)
如果服务(在端口上8080)关闭,它工作正常,但是当服务启动并且我尝试访问 url /error.htmlnginx 匹配最后一个位置(返回静态文件)时,我想避免它。
好吧,如果你真的不想暴露错误页面,你可以使用命名位置。
server {
listen 80;
server_name default;
location / {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080/;
# probably you also need this
# proxy_intercept_errors on;
}
error_page 404 502 @error;
location @error {
root /var/www;
try_files /error.html /error.html;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1628 次 |
| 最近记录: |