我在nginx.conf中有HTTPS重定向
WordPress + Nginx (+Vestacp)
server {
listen x.x.x.x:80;
server_name test.com www.test.com;
root /home/admin/web/test.com/web/;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/test.com.log combined;
access_log /var/log/nginx/domains/test.com.bytes bytes;
error_log /var/log/nginx/domains/test.com.error.log error;
return 301 https://test.com$request_uri;
}发布于 2021-07-10 04:17:32
欢迎来到ServerFault。
但是如果请求的URI是HTTP和404 -我不需要重定向。这个特定的配置有什么解决方案吗?
我不知道该怎么做。我不确定这是否可能。
此外,是否有可能关闭HTTPS + www重定向的404链接,如http://www.test.com
我不明白这个问题。
如果不能完成第1或第2点,我是否可以用nginx硬编码404 URL列表,以便完全关闭任何重定向,只显示404页?(HTTPS和www)
这是可能的。假设我们在/home/admin/web/test.com/web/404.conf上有以下格式的文件列表.
/aboutt-us/ 404;
/about-uss/ 404;
/contactt-us/ 404;
/contact-uss/ 404;除了"0“(0)之外,我们可以不使用文本"404”。
修改后的配置会像这样..。
map $uri $allwillburnn { include /home/admin/web/test.com/web/404.conf; }
server {
listen x.x.x.x:80;
server_name test.com www.test.com;
root /home/admin/web/test.com/web/;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/test.com.log combined;
access_log /var/log/nginx/domains/test.com.bytes bytes;
error_log /var/log/nginx/domains/test.com.error.log error;
if ( $allwillburnn ) { return 404; }
return 301 https://test.com$request_uri;
}说明:默认情况下,对于上述404.conf文件中没有列出的任何URL,名为$allwillburnn的变量由地图分配给0(零)值。在这种情况下,跳过如果块,从而导致301个重定向。
对于404.conf文件中列出的URL,$allwillburnn被分配给非零值.在本例中,如果解析了块,则生成404。
我希望这能帮上忙。
https://serverfault.com/questions/1069091
复制相似问题