Pri*_*hra 6 https redirect nginx
我想将所有http
流量重定向到https
。我正在使用letsencrypt
。我在网上阅读了内容,该链接return 301 https://$server_name$request_uri;
会将所有访问量重定向到我的网站,https
但最终导致ERR_TOO_MANY_REDIRECTS
。
没有上面提到的语句,一切都可以正常工作,但是然后我必须https
在URL中专门指定。这是我的/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;
}
}
Run Code Online (Sandbox Code Playgroud)
我要去哪里错了?
ZyQ*_*Qux 34
就我而言,它是 Cloudflare。我不得不改为完全 SSL 加密
将您的配置更改为以下
server {
listen 80 default_server;
server_name mywebsite.me www.mywebsite.me;
return 301 https://$server_name$request_uri;
}
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;
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;
}
}
Run Code Online (Sandbox Code Playgroud)
您当前的配置在http和https上都重定向到https。因此,由于return语句,它变成了无限循环。仅在连接为http时才需要return语句。所以您将其分为两个服务器块
我有同样的问题。我发现了很多关于它的问题/答案和文章,但没有任何帮助。然后我尝试从不同的浏览器访问我的网站,它工作得很好!从我的 Chrome 浏览器中删除缓存解决了这个问题。
所以 - 当您尝试不同的解决方案来清除缓存时请记住
归档时间: |
|
查看次数: |
11045 次 |
最近记录: |