如何在 nginx 中将整个域标记为 410 Gone?
How to mark an entire domain as 410 Gone in nginx?
作为使网站停止运行的一部分,我想配置 nginx 为所有 URL 发送 410 Gone。最简单的配置是这样的:
server {
listen 127.0.0.1:8080;
server_name example.ch www.example.ch;
root /srv/www/sites/example.ch/public;
return 410;
}
这似乎应该可行,但出于某种原因,当我转到域的根目录时,我反而得到了 404 Not Found,如果我转到任何其他 URL,我得到nginx 错误日志中出现 500 内部服务器错误和此消息:
rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 127.0.0.1, server: localhost, request: "GET /adsf HTTP/1.1", host: "example.ch:8080"
这对我来说意义不大。我也尝试用 error_page 404 =410 410.html;
替换 return 410
,甚至将 return 410
包装在 location / {}
块中,但结果完全一样。
谁能帮我弄清楚这是怎么回事?
原来问题是我在我的服务器块中混合了 listen 127.0.0.1:8080;
和 listen 8080;
,这就是本例中的问题。
所以这个配置效果很好:
server {
listen 8080; # Because I have Varnish in front of nginx.
server_name example.ch www.example.ch;
root /srv/www/sites/example.ch/public;
return 410;
}
作为使网站停止运行的一部分,我想配置 nginx 为所有 URL 发送 410 Gone。最简单的配置是这样的:
server {
listen 127.0.0.1:8080;
server_name example.ch www.example.ch;
root /srv/www/sites/example.ch/public;
return 410;
}
这似乎应该可行,但出于某种原因,当我转到域的根目录时,我反而得到了 404 Not Found,如果我转到任何其他 URL,我得到nginx 错误日志中出现 500 内部服务器错误和此消息:
rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 127.0.0.1, server: localhost, request: "GET /adsf HTTP/1.1", host: "example.ch:8080"
这对我来说意义不大。我也尝试用 error_page 404 =410 410.html;
替换 return 410
,甚至将 return 410
包装在 location / {}
块中,但结果完全一样。
谁能帮我弄清楚这是怎么回事?
原来问题是我在我的服务器块中混合了 listen 127.0.0.1:8080;
和 listen 8080;
,这就是本例中的问题。
所以这个配置效果很好:
server {
listen 8080; # Because I have Varnish in front of nginx.
server_name example.ch www.example.ch;
root /srv/www/sites/example.ch/public;
return 410;
}