我有一个在LEMP堆栈上运行的网站.我已经在网站上启用了cloudflare.我正在为https使用cloudflare灵活SSL证书.当我在chrome中打开网站时,它显示网站重定向了你太多次,并且在firefox中检测到服务器正在以永远不会完成的方式重定向该地址的请求.我试图看到其他问题的答案,但似乎都没有解决问题.NGINX conf文件: -
server { listen 80 default_server; listen [::]:80 default_server; server_name mydomain.com www.mydomain.com; return 301 https://$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; } }
如果有人能指出我做错了什么,我将非常感激.
由于您使用的是cloudflare灵活SSL,因此您的nginx配置文件将如下所示: -
server { listen 80 default_server; listen [::]:80 default_server; server_name mydomain.com www.mydomain.com; if ($http_x_forwarded_proto = "http") { return 301 https://$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; } }