我想将所有 http
流量重定向到 https
。我正在使用 letsencrypt
。我在网上读到 return 301 https://$server_name$request_uri;
会将所有到我网站的流量重定向到 https
,但结果却是 ERR_TOO_MANY_REDIRECTS
.
如果没有上面提到的语句,一切都会正常工作,但是我必须在 URL 中专门指定 https
。这是我的 /etc/nginx/sites-available/default
文件:
server {
listen 80 default_server;
listen 443 ssl default_server;
ssl_certificate /etc/letsencrypt/live/mywebsite.me/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.me/privkey.pem;
root /home/website/mywebsite/public;
index index.html index.htm index.php;
server_name mywebsite.me www.mywebsite.me;
return 301 https://$server_name$request_uri;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
}
}
我哪里出错了?
最佳答案
就我而言,它是 Cloudflare。我不得不更改为完全 SSL 加密
关于redirect - nginx 的 ERR_TOO_MANY_REDIRECTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46413494/