HTTP到HTTPS Nginx的重定向过多

编程入门 行业动态 更新时间:2024-10-21 05:35:08
本文介绍了HTTP到HTTPS Nginx的重定向过多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个运行在LEMP堆栈上的网站.我已通过网站启用cloudflare.我正在将cloudflare灵活SSL证书用于https.当我在Chrome中打开网站时,它表明网站重定向了您太多次,并且在Firefox中检测到服务器正在以永远无法完成的方式重定向对该地址的请求.我尝试查看其他问题的答案,但似乎都无法解决问题. NGINX conf文件:-

I have a website running on a LEMP stack. I have enabled cloudflare with the website. I am using the cloudflare flexible SSL certificate for https. When i open the website in chrome it shows website redirected you too many times and in firefox has detected that the server is redirecting the request for this address in a way that will never complete. I have tried to see answers of other questions but none of them seem to solve the problem. NGINX conf file:-

server { listen 80 default_server; listen [::]:80 default_server; server_name mydomain www.mydomain; return 301 $server_name$request_uri; } server { listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } }

如果有人能指出我做错了事,我将不胜感激.

I would be highly grateful if anyone can point out what I am doing wrong.

推荐答案

由于您正在使用cloudflare flexible SSL,因此您的nginx配置文件将如下所示:-

Since you are using cloudflare flexible SSL your nginx config file wll look like this:-

server { listen 80 default_server; listen [::]:80 default_server; server_name mydomain www.mydomain; if ($http_x_forwarded_proto = "http") { return 301 $server_name$request_uri; } root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } }

更多推荐

HTTP到HTTPS Nginx的重定向过多

本文发布于:2023-10-31 16:18:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546615.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   HTTP   HTTPS   Nginx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!