【发布时间】:2019-06-16 08:35:51
【问题描述】:
尝试将位置从 https 重定向到 http,在浏览器中获得重定向循环。
P.S 我已经安装了 certbot (Let's Encrypt) 来获取 ssl 证书。
我尝试了不同的服务器块,相同的服务器块,返回 301,重写,但似乎没有任何效果。
server {
root /usr/share/nginx/www;
index index.html index.htm index.php;
server_name example.com;
# Make site accessible from http://localhost/
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location /update {
return 301 http://example.com$request_uri;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name example.com;
return 404; # managed by Certbot
}
我想让https://example.com/update/ 重定向到http://example.com/update/
【问题讨论】:
-
您的第二个
server块只是将http重定向回https。在开始重定向到http://example.com/update/之前,您需要决定如何处理它。 -
不返回结束文件?无论如何,我将第二个服务器块移到了第一个之上,这没有任何区别。对此很新,所以我不完全了解如何对其进行编辑以使其正常工作。