VPS侦探论坛

 找回密码
 注册
查看: 5889|回复: 3

LNMP V1.3 怎么强制使用 HTTPS 访问 【已解决】

[复制链接]
发表于 2015-11-12 13:45:32 | 显示全部楼层 |阅读模式

军哥,我在域名conf设置了只监听443端口,但是这样的话,域名80端口访问就访问到默认目录/home/wwwroot/default里面去了。使用 https://域名.com可以正常访问。怎么解决呢 ?

[ 本帖最后由 nic2013 于 2015-11-12 19:21 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2015-11-12 17:12:57 | 显示全部楼层


参考301教程,将http上的访问301到https上 http://lnmp.org/faq/lnmp-nginx-301-rewrite.html
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2015-11-12 19:21:11 | 显示全部楼层

回复 2# 的帖子


不行哦,此网页包含重定向循环。我瞎捣鼓,用下面的方法弄好了。
server
    {
        listen 80;
        listen 443 ssl;
        #listen [::]:80;
if ($server_port ~ "^80$"){
set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
rewrite /(.*) https://域名.com/$1 permanent;
break;
}
index index.html index.htm index.php default.html default.htm default.php;
root  /home/wwwroot/www.域名.com;

ssl on;
        ssl_certificate /root/ssl.crt;
        ssl_certificate_key /root/ssl.key;
        server_name www.域名.com 域名.com;
        index index.html index.htm index.php default.html default.htm default.php;

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

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

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

        access_log  /home/wwwlogs/域名.com.log  access;
    }
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2015-11-12 19:39:07 | 显示全部楼层

回复 3# 的帖子




肯定你配置问题

这种if效率很低,非常不建议使用if
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-28 13:21 , Processed in 0.025962 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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