laravel nginx 下配置https问题

各位大神,小弟今天使用lnmp一键安装了nginx的环境, php是7.0+的。
上传laravel5.5的程序到服务器端,http访问正常。
配置https的时候出现了问题,找了很多资料都不行,求助啊!
小弟测试N久出来了两种问题:

第一种问题, 证书没问题, 但是网站不能访问:

图片描述

问题1:

如果注释掉 include pathinfo.conf 这一行,-> 证书没问题, 但是报错 No input file specified.

问题2:

如果放开 include pathinfo.conf 这一行,-> 证书没问题, 但是报错404下图
图片描述

第二种问题, 证书不行, 但网站可以访问
图片描述

问题: 如果把index 和 root 这2行放到 location / 外面 网站可以了,但是证书不行, 反之放进来证书可以了,网站不行了
所有代码
server {
    listen       443 ssl;
    server_name  www.baidu.com;

    ssl on;
    ssl_certificate      /cn_bundle.crt;
    ssl_certificate_key  /cn.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    #禁止在header中出现服务器版本,防止黑客利用版本漏洞攻击
    server_tokens off;

     #如果是全站 HTTPS 并且不考虑 HTTP 的话,可以加入 HSTS 告诉你的浏览器本网站全站加密,并且强>制用 HTTPS 访问
    #add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
    # ......
    #fastcgi_param   HTTPS               on;
    #fastcgi_param   HTTP_SCHEME         https;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;


    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;



    location / {
       index index.html index.htm index.php default.html default.htm default.php forum.php;
       root /home/wwwroot/default/laravel/public;

       try_files $uri $uri/ /index.php?$query_string;


    }

   if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=$1  last;
            break;
    }


    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;
       # include pathinfo.conf;
    }


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

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



}

使用的腾讯云的免费证书。望大神给与指点。

阅读 6.5k
3 个回答

root和index 放到server 域,就是location 外面,不然,你下面的所有location域都找不到 网站根目录在哪里。

下面的if条件判断是为了啥啊? try_files 和 !-e 下面的逻辑不一样,你到底需要哪一个?把需要得改成 try_files 的格式,放到location /下去。

然后放开 pathinfo.conf的引入 。。

如果把root和index 两行 放到 location / 里面 证书就是绿色的,没问题, 如果把root和index 放到 ocation /外面 证书就不灰色的,就不行了
图片描述

图片描述

root放在location 外面,证书放在配置目录同一级目录下,或者证书随便放, ssl_certificate /xxx/xxx/cn_bundle.crt;关键配置中证书的加载路劲要对

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题