amo 大佬有话说 :
nginx网站http自动跳转https怎么做
本帖最后由 amo 于 2020-6-12 10:37 编辑
宝塔是这样写的 ,但是百度蜘蛛抓取,抓取异常信息: socket 读写错误,关掉强制SSL就正常
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
还有其他写法没有,大家推荐几个我试试
if ($scheme = http ) {
return 301 https://$host$request_uri;
}
if ($server_port = 80 ) {
return 301 https://$host$request_uri;
}
if ($ssl_protocol = "") { rewrite ^ https://$server_name$request_uri? permanent; }
以上写法都是重定向过多。。。。
好像只要写了return 就是重定向过多,,,,
不想分开写了,谁给看看怎么写
server
{
listen 80;
listen 443 ssl http2;
server_name www.11111.com 11111.com;
index index.html index.php index.htm;
root /www/wwwroot/www.11111.com;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
ssl_certificate /www/server/panel/vhost/cert/www.11111.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/www.11111.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497https://$host$request_uri;
#SSL-END
#ERROR-PAGE-START错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-STARTPHP引用配置,可以注释或修改
include enable-php-53.conf;
#PHP-INFO-END
#禁止访问的文件或目录
location ~ ^/(.user.ini|.htaccess|.git|.svn|.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ .well-known{
allow all;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*.(js|css)?$
{
expires 12h;
error_log off;
access_log /dev/null;
}
access_log/www/wwwlogs/www.11111.com.log;
error_log/www/wwwlogs/www.11111.com.error.log;
}
不想分开写了,谁给看看怎么写
FeiLai 大佬有话说 :
看这篇文章:https://www.wmsoho.com/lnmp-nginx-http-to-https-without-www/
夕日 大佬有话说 :
本帖最后由 夕日 于 2020-6-12 09:53 编辑
server {
listen 80;
server_name xxx.xxx;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name xxx.xxx;
……
……
}
我一般都是这样,301重定向yc022t
流河旱树 大佬有话说 :
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
amo 大佬有话说 :
FeiLai 大佬有话说 : 2020-6-12 09:50
看这篇文章:https://www.wmsoho.com/lnmp-nginx-http-to-https-without-www/
server
{
listen 80;
server_name www.11111.com 11111.com;
return 301 https://www.11111.com$request_uri;
index index.html index.php index.htm;
root /www/wwwroot/www.11111.com;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-STARTPHP引用配置,可以注释或修改
include enable-php-53.conf;
#PHP-INFO-END
access_log/www/wwwlogs/www.11111.com.log;
error_log/www/wwwlogs/www.11111.com.error.log;
}
server
{
listen 443 ssl http2;
server_name 11111.com;
return 301 https://www.11111.com$request_uri;
index index.html index.php index.htm;
root /www/wwwroot/www.11111.com;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
ssl_certificate /www/server/panel/vhost/cert/www.11111.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/www.11111.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497https://$host$request_uri;
#SSL-END
#ERROR-PAGE-START错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-STARTPHP引用配置,可以注释或修改
include enable-php-53.conf;
#PHP-INFO-END
access_log/www/wwwlogs/https.www.11111.com.log;
error_log/www/wwwlogs/https.www.11111.com.error.log;
}
我按这样写 不行的,直接网页打不开 重定向过多
Ticifer 大佬有话说 :
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
amo 大佬有话说 :
不行啊 都是重定向过多 好像也没其他重定向了 怎么回事
cheshirex 大佬有话说 :
套CDN没?套了的话用https443回源