【发布时间】:2016-02-24 07:08:04
【问题描述】:
如果您有免费的 cloudflare 计划,或启用了 cloudflare,则会导致无限重定向循环。
我正在尝试使用 nginx 将 http 重定向到 https。我已经尝试过(几乎)一切。我试过正则表达式,301重定向和返回。
我不确定,但可能与配置文件有关。我使用 Let's Encrypt for SSL 和 php7.0.5-fpm 处理脚本。
server {
listen 443 ssl;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
location ~ /.well-known {
allow all;
}
}
server {
listen 80 default_server;
return 301 https://$http_host$request_uri;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php;
server_name example.com;
error_page 500 /500.html;
error_page 404 /404.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
编辑这里是命令ls -lah:
total 44K
drwxrwxrwx 6 root root 4.0K Feb 28 22:12 .
drwxrwxrwx 3 root root 4.0K Feb 20 21:19 ..
-rw-rw-rw- 1 rsudo rsudo 396 Feb 21 15:52 404.php
drwxrwxrwx 8 rsudo rsudo 4.0K Feb 21 15:50 assets
drwxrwxrwx 3 rsudo rsudo 4.0K Feb 21 15:48 backend
-rw-rw-rw- 1 rsudo rsudo 360 Feb 21 18:20 .htaccess
drwxrwxrwx 2 rsudo rsudo 4.0K Feb 21 15:49 includes
-rw-rw-rw- 1 root root 612 Feb 28 22:12 index.nginx-debian.html
-rw-rw-rw- 1 rsudo rsudo 21 Feb 21 03:36 info.php
-rw-rw-rw- 1 rsudo rsudo 2.4K Feb 21 15:58 login.php
drwxrwxrwx 3 root root 4.0K Feb 23 23:10 .well-known
配置:
server {
listen 80;
error_log /var/log/nginx/1.log;
access_log /var/log/nginx/2.log;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
access_log /var/log/nginx/1ssl.log;
error_log /var/log/nginx/2ssl.log;
# Add index.php to the list if you are using PHP
index index.php;
error_page 500 /500.html;
error_page 404 /404.php;
server_name example.com;
root /var/www/html;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
location ~ /.well-known {
allow all;
}
location / {
#So lonely...
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
【问题讨论】:
-
我看到
.well-known部分,您是通过Let's Encrypt配置HTTPS 吗?如果是,那部分应该放在80端口。 -
ssl 应该进入端口 80 块?我也在使用 Let's Encrypt。