技术解析

如何全站启用 https 访问,按照网上教程来写配置的话网站会无限重定向。
0
2021-05-27 23:58:41
idczone
国外服务器
server {
listen 80;
server_name www.xxx.com xxx.com;
return 301 https://www.xxx.com$request_uri;
}
server {
listen 443;
server_name xxx.com;
return 301 https://www.xxx.com$request_uri;
}
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
server {
listen 443 default_server ssl;
server_name www.xxx.com;
keepalive_timeout 70;
ssl_certificate /etc/nginx/ssl/ssl-unified.crt;
ssl_certificate_key /etc/nginx/ssl/ssl2.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
這個配置都會重定向到 https://www.xxx.com

額,發錯了,不是全站的,題主無視吧

把你的配置发来看看,我给你改

nginx的配置
你参考一下,改成自己的目录和域名
server
{
listen 80;
[::]:80;
server_name www.gfw.im gfw.im;
rewrite ^/(.*) https://www.gfw.im/$1 permanent;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.gfw.im;
include wordpress.conf;
404 /404.html;
location ~ [^/]\.php(/|$)
{
comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/www.gfw.im.log access;
}
server
{
listen 443 ssl spdy;
ssl on;
ssl_certificate /home/wwwroot/ssl/ssl.crt;
ssl_certificate_key /home/wwwroot/ssl/ssl.key.out;
ssl_session_timeout 5m;
[::]:80;
server_name www.gfw.im gfw.im;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.gfw.im;
include wordpress.conf;
404 /404.html;
location ~ [^/]\.php(/|$)
{
comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/www.gfw.im.log access;
}

建议检查下程序有没有启用SSL的选项,有可能是你的程序设定了强制使用协议http,Nginx跳到https后程序只认http又跳转回http,nginx识别到http后又跳回https上,然后就死循环了,一些程序没有给出SSL选项就只能在源码中找到写死http的部分改成https来解决。

我的配置,给你参考一下
server {

listen 80;
server_name hack0nair.me;
location / {
rewrite ^(.*)$ https://hack0nair.me$1 permanent;
}
}
HTTPS server
server {
listen 443 ssl;
server_name hack0nair.me;
ssl_certificate /root/ssl/hack0nair.me.crt;
ssl_certificate_key /root/ssl/hack0nair.me.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RC4-SHA:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!DSS:!PKS;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_stapling on;
ssl_stapling_verify on;
location / {
root /var/www/hack0nair.me;
index index.html;
}
}

我用的是hexo。无限重定向nginx配置文件同一楼。

用了你的也是太多重定向。 = =。

find /path/to/hexo | grep "http:"
全改成 https

曾经遇到过,如果是多站点SSL跳的话记得要proxy_set_header Host $host; 否则有可能会因为后端应用的问题无限跳转。

搞定了。重新完整的弄了一下。

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服