开发者社区> 问答> 正文

为什么nginx php-fph 已经设置conf文件重定向 还是不能自动转https?

如题,已经根据教程设置http 301重定向https,证书也在vestacp面板内植入成功,手动输入https://*****.com可以进入,但是****.com就还是打开http?


那么手动输入https能成功进入,证明ssl证书是有效的没有问题的;那我分析只能是重定向的问题是么?


server 内部分代码:     listen  80;
    server_name ××××.com www.×××××.com;
    rewrite ^(.*) https://×××××.com$1 permanent;


Thanks!谢谢!



展开
收起
timhorton 2017-04-16 09:00:37 3635 0
3 条回答
写回答
取消 提交回答
  • 回 2楼梦丫头的帖子
    正解
    2017-04-18 09:58:57
    赞同 展开评论 打赏
  • 回 楼主timhorton的帖子
    "在nginx文件夹下找到对应的虚拟主机配置文件,路径为:www/wdlinux/nginx/conf/vhost "

    谢谢版主回复!

    为什么我的centos7.3系统安装的nginx php-fpm后没有vhost这个,我的是根据网上教程自己加了一个conf配置文件,也关联了,curl -I www.***.com显示这样:

    HTTP/1.1 301 Moved Permanently
    Server: nginx
    Date: Sun, 16 Apr 2017 03:11:59 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Keep-Alive: timeout=60
    X-Powered-By: PHP/5.6.30
    Location: http://×××××.com/

    还是不成功?是不是应该curl测试最后的Location:http应该是https?就对了?
    显示“HTTP/1.1 301 Moved Permanently”是不是证明301重定向起作用了。

    谢谢!

    补充:刚试了下,现在是这样子的:
    输入域名××××.com 不能直接跳转https://××××.com,但是进去之后点击站内其他链接,打开的都是https链接。
    这是为啥?不能输入域名直接打开首页就是https网址吗?

    非常感谢!
    2017-04-16 11:16:45
    赞同 展开评论 打赏
  • 论坛总版主
    在nginx文件夹下找到对应的虚拟主机配置文件,路径为:www/wdlinux/nginx/conf/vhost

    然后对该虚拟主机配置文件做如下修改:


    server {
          
            listen 443;

            root /www/web/guwanlife/public_html;
            server_name www.test.com www.test.com;
            index  index.html index.php index.htm;
            error_page  400 /errpage/400.html;
            error_page  403 /errpage/403.html;
            error_page  404 /errpage/404.html;
            error_page  503 /errpage/503.html;
            ssl on;
    ssl_certificate_key  /www/wdlinux/nginx/conf/pastdust.key;
    ssl_certificate  /www/wdlinux/nginx/conf/pastdust.crt;

            location ~ \.php$ {
                    fastcgi_pass   127.0.0.1:9000;
                    fastcgi_index  index.php;
                    include fcgi.conf;
            }
            location ~ /\.ht {
                    deny  all;
            }
            include /www/wdlinux/wdcp/rewrite/dzx32_nginx.conf;
    }
      server {
        listen      80;
        server_name    www.test.com;
        return      301 https://$server_name$request_uri;
    }



    蓝色部分为rewrite规则,原理是监听443端口使用https,监听80端口使用301重定向到https.

    -------------------------

    主要是这段
    }
      server {
        listen      80;
        server_name    www.test.com;
        return      301 https://$server_name$request_uri;
    }

    2017-04-16 10:05:59
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
CDN助力企业网站进入HTTPS时代 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载