【发布时间】:2015-10-04 14:24:59
【问题描述】:
我正在尝试指定自定义 404 页面并保留 URL,但是使用下面的代码会给我错误 nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in...
location / {
error_page 404 @404;
}
location @404 {
proxy_pass https://example.com/404.html;
}
有人知道解决办法吗?
【问题讨论】:
-
为什么你需要为那个
404.html使用代理? -
我想在不同的站点/域/服务器块之间共享 404 页面。即我想将来自example.com/404.html 的404 页面用于test.example.com 和其他使用不同服务器块的域。
-
我明白了,因为保留了 URL。如果 nginx 不喜欢命名位置,请尝试不存在的位置:
error_page 404 /404/non-exist; location /404/non-exist { ... } -
是的,完全是为了保留 URL。您能否将您的代码块放入答案中,以便其格式正确,如果它有效,我可以接受它作为答案?谢谢
标签: nginx proxy rewrite http-status-code-404 proxypass