Nginx在添加SSL证书后导致无限重定向循环。

6 浏览
0 Comments

Nginx在添加SSL证书后导致无限重定向循环。

我在我的网站上添加了SSL证书,结果导致了重定向循环。之前一切正常。我尝试了以下解决方法:

以及其他我找到的解决方案,我怀疑可能与文件权限有关,但我没有找到任何问题。我还尝试将我的crt和key文件放在/etc/ssl目录下。这是我的default.website文件:server { listen 80; server_name www.example.com example.com; rewrite ^ https://$server_name$request_uri? permanent; } server { listen 443; ssl on; ssl_certificate /etc/nginx/ssl/ssl-bundle.crt; ssl_certificate_key /etc/nginx/ssl/private.key; server_name example; access_log /var/log/nginx/whcms.log; location / { root /usr/share/nginx/html/example.com; index index.php index.html; try_files $uri $uri/ /index.php?$args; } location /ngx_status_2462 { stub_status on; access_log off; allow all; } location ~ \\.php$ { fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/example.com$fastcgi_script_name; fastcgi_param CCODE $geoip_country_code; include fastcgi_params; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } 这是我的nginx.conf文件:user nginx; worker_processes 12; worker_rlimit_nofile 100000; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 100000; use epoll; } http { include /etc/nginx/mime.types; default_type application/octet-stream; keepalive_requests 0; log_format main \'$remote_addr - $remote_user [$time_local] \"$host\" \"$request\" \' \'$status $body_bytes_sent \"$http_referer\" \' \'\"$http_user_agent\" \"$http_x_forwarded_for\"\'; set_real_ip_from 0.0.0.0/0; real_ip_header CF-Connecting-IP; geoip_country /usr/share/GeoIP/GeoIP.dat; access_log /var/log/nginx/nginx-access.log main buffer=256k; sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; ## Caching files ... ## Size Limits ... ## Timeouts ... ## Compression ... #include /etc/nginx/sites-enabled/*; # Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf; index index.php index.html index.htm; include /etc/nginx/websites/*.website; } 这是错误日志(添加了调试):2015/11/03 09:22:09 [notice] 30330#0: *1 \"^\" matches \"/\", client: , server: example.com, request: \"GET / HTTP/1.1\", host: \"example.com\" 2015/11/03 09:22:09 [notice] 30330#0: *1 rewritten redirect: \"https://example.com/\", client: , server: example.com, request: \"GET / HTTP/1.1\", host: \"example.com\" 2015/11/03 09:22:10 [notice] 30330#0: *2 \"^\" matches \"/\", client: , server: example.com, request: \"GET / HTTP/1.1\", host: \"example.com\" 2015/11/03 09:22:10 [notice] 30330#0: *2 rewritten redirect: \"https://example.com/\", client: , server: example.com, request: \"GET / HTTP/1.1\", host: \"example.com\" 2015/11/03 09:22:10 [notice] 30330#0: *1 \"^\" matches \"/\", client: , server: example.com, request: \"GET / HTTP/1.1\", host: \"example.com\" 其中是服务器IP地址。我使用CloudFlare作为我的DNS提供商。

0
0 Comments

Nginx在添加SSL证书后导致无限重定向循环的问题可能是由于server_name设置错误所导致的。解决方法是将443服务器中的server_name更正为正确的域名,并将listen 443更改为listen 443 ssl。

首先,检查443服务器中的server_name是否设置正确。如果server_name设置错误,可能会导致无限重定向循环。确保server_name设置与实际域名匹配。

其次,检查443监听的设置。正确的设置应该是listen 443 ssl;。确保在443监听中包含了ssl选项。

如果你正在使用AWS ELB(亚马逊云负载均衡器),请确认是否配置正确。对于自己搭建的服务器,需要将listen 443修改为listen 443 ssl;

总结一下,当在Nginx中添加SSL证书后导致无限重定向循环的问题时,首先要检查server_name是否设置正确,其次要确保在443监听中包含了ssl选项。如果使用AWS ELB,请确认配置正确。根据以上步骤进行调整后,问题应该得到解决。

0