VPS侦探论坛

 找回密码
 注册
查看: 3505|回复: 4

[Apache] 有关nginx 301的问题

[复制链接]
发表于 2017-8-10 20:36:57 | 显示全部楼层 |阅读模式

在nginx的配置文件里添加了301的代码:

如下:
if ($server_port = 80)
{
return 301 https://$server_name$request_uri;
}
if ($scheme = http)
{
return 301 https://$server_name$request_uri;



都能301跳转。后来发现一个问题。

新开了一个域名的解析,就是二级域名,服务器的IP和原来的不一样。
原来的服务器IP是:1.1.1.1   绑定域名:5137bj.com  www.5137bj.com
新的二级域名的服务器IP是:2.2.2.2  绑定域名:mp.5137bj.com

我在配置文件里一开启上面的301跳转代码,就会出现:
打开http://mp.5137bj.com  就会以https方式打开。也就是https://mp.5137bj.com

问题是,2.2.2.2没有做任何的https的协议配置啊。

请教一下军哥和各位。

https的证书,我只用5137bj.com和www.5137bj.com来申请的。而且是两台服务器哦。
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2017-8-11 08:57:42 | 显示全部楼层


你前面的301代码你加到哪里了?加的位置不对肯定所有域名都跳到https上
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2017-8-11 16:08:15 | 显示全部楼层

回复 2# 的帖子


代码加在server这层里。。

配置文件如下:
server
    {
        listen 80;
        listen 443 ssl;
        #listen [::]:80;
        server_name 5137bj.com www.5137bj.com;
        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/**/5137bj.com;
        

        include wordpress.conf;
        #error_page   404   /404.html;
        include enable-php.conf;

        ssl on;
        ssl_certificate /usr/*/*/5137bj.crt;
        ssl_certificate_key /usr/*/*/5137bj.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;

if ($server_port = 80)
{
return 301 https://$server_name$request_uri;
}
if ($scheme = http)
{
return 301 https://$server_name$request_uri;
}

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

location = /robots.txt {
        if ($http_user_agent !~* "spider|bot|Python-urllib|pycurl")
                {
                return 403;
                }
        }

        access_log  /*/**.log;
    }
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2017-8-11 17:40:12 | 显示全部楼层

回复 3# 的帖子




add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload"; 你自己设置的让全部域名包含二级域名都强制https,而且有效期是365天,到期以前,访问过该域名的浏览器都会记录下来强制https,除非手动清空浏览器里的HSTS缓存
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2017-8-12 15:39:48 | 显示全部楼层

回复 4# 的帖子


非常感谢军哥。

问题得到了解决!!!!

军哥运维代购:http://shop63846532.taobao.com/

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-5-8 02:57 , Processed in 0.026741 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表