鍍金池/ 問答/PHP  Linux  網(wǎng)絡(luò)安全  HTML/ laravel nginx 下配置https問題

laravel nginx 下配置https問題

各位大神,小弟今天使用lnmp一鍵安裝了nginx的環(huán)境, php是7.0+的。
上傳laravel5.5的程序到服務(wù)器端,http訪問正常。
配置https的時(shí)候出現(xiàn)了問題,找了很多資料都不行,求助??!
小弟測(cè)試N久出來了兩種問題:

第一種問題, 證書沒問題, 但是網(wǎng)站不能訪問:

圖片描述

問題1:

如果注釋掉 include pathinfo.conf 這一行,-> 證書沒問題, 但是報(bào)錯(cuò) No input file specified.

問題2:

如果放開 include pathinfo.conf 這一行,-> 證書沒問題, 但是報(bào)錯(cuò)404下圖
圖片描述

第二種問題, 證書不行, 但網(wǎng)站可以訪問
圖片描述

問題: 如果把index 和 root 這2行放到 location / 外面 網(wǎng)站可以了,但是證書不行, 反之放進(jìn)來證書可以了,網(wǎng)站不行了
所有代碼
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中出現(xiàn)服務(wù)器版本,防止黑客利用版本漏洞攻擊
    server_tokens off;

     #如果是全站 HTTPS 并且不考慮 HTTP 的話,可以加入 HSTS 告訴你的瀏覽器本網(wǎng)站全站加密,并且強(qiáng)>制用 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;
    }



}

使用的騰訊云的免費(fèi)證書。望大神給與指點(diǎn)。

回答
編輯回答
蔚藍(lán)色

如果把root和index 兩行 放到 location / 里面 證書就是綠色的,沒問題, 如果把root和index 放到 ocation /外面 證書就不灰色的,就不行了
圖片描述

圖片描述

2017年3月11日 12:06
編輯回答
瞄小懶

root和index 放到server 域,就是location 外面,不然,你下面的所有l(wèi)ocation域都找不到 網(wǎng)站根目錄在哪里。

下面的if條件判斷是為了啥啊? try_files 和 !-e 下面的邏輯不一樣,你到底需要哪一個(gè)?把需要得改成 try_files 的格式,放到location /下去。

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

2017年9月29日 23:20
編輯回答
鹿惑

root放在location 外面,證書放在配置目錄同一級(jí)目錄下,或者證書隨便放, ssl_certificate /xxx/xxx/cn_bundle.crt;關(guān)鍵配置中證書的加載路勁要對(duì)

2017年11月26日 14:55