作者 主題: nginx vhost 中 https 的設定問題  (閱讀 3454 次)

0 會員 與 1 訪客 正在閱讀本文。

keivn

  • 可愛的小學生
  • *
  • 文章數: 3
    • 檢視個人資料
nginx vhost 中 https 的設定問題
« 於: 2018-02-28 11:37 »
各位大大好:
小弟目前nginx的環境中,有10個vhost,均正常運作中。
但,其中的一個網域,使用Let’s Encrypt SSL,也可正常使用443連入網站裡面,例如網址:https://www.E.com.tw運作也正常(vhost中,唯一使用https的網址)。
隔了幾天之後,在google用關鍵字搜尋,卻發現到,以http為主的其它網站,卻在google的搜尋頁面中出現,例如搜尋『汽車』的結果,卻出現
https://www.a.com.tw、https://www.b.com.tw、https://www.c.com.tw 等等的網址(非https的設定網址),卻出現在google的搜尋頁面當中,標題和搜尋內容是E網站的正確資訊,而網址卻是a、b、c...等等。
也訧是google搜尋的結果,是https://www.E.com.tw,這個網站的正確內容,而google頁面中的連結網址卻是連進其它a、b、c...的網站,而不是進入https://www.E.com.tw,而出現『你的連線不是私人連線』,因為網址連錯了跑到https://www.a.com.tw這個網域中。

我的 https://www.E.com.tw 設定如下:
server {
        listen       443 default_server ssl;
        server_name     www.E.com.tw E.com.tw;
        error_page      404 403 500 502 503 504 /ER404.php;

        location / {
                root    /var/www/Edir;
                index   index.html index.php;
        }

        location ~ \.php$ {
                root            /var/www/Edir;
                fastcgi_pass    127.0.0.1:9071;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include         fastcgi_params;
        }
      .
      .
      .
      .
      .
      
}
server {
   listen   80;
   server_name www.E.com.tw E.com.tw;
   return 301 https://www.E.com.tw$request_uri;
}

而其它的http設定如下:
server {
   listen   80;
   server_name   www.a.com.tw a.com.tw;
   error_page   404 403 500 502 503 504 /ER404.php;

   location / {
      root    /var/www/Adir;
      index   index.html index.htm index.php;
   }

   location ~ \.php$ {
      root            /var/www/Adir;
      fastcgi_pass    127.0.0.1:9071;
      fastcgi_index   index.php;
      fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include         fastcgi_params;
   }

   location ~ /.well-known { allow all; }
   location ~ /\. { deny all; }
}

煩請各位大大不吝指導,感恩。

darkranger

  • 榮譽學長
  • 俺是博士!
  • *****
  • 文章數: 1382
    • 檢視個人資料
    • https://darkranger.no-ip.org
Re: nginx vhost 中 https 的設定問題
« 回覆 #1 於: 2018-02-28 20:48 »
非 https 的 vhost 做 port 443 重定向到 port 80 看看

keivn

  • 可愛的小學生
  • *
  • 文章數: 3
    • 檢視個人資料
Re: nginx vhost 中 https 的設定問題
« 回覆 #2 於: 2018-03-01 11:18 »
感謝大大的回覆,感恩。
在非https的vhost中,重定到80埠,如下:
server {
    listen 443;
    server_name www.a.com.tw a.com.tw;
    rewrite ^(.*)$ http://${server_name}$1 permanent;
}
還是無法導回,如果有導回,在google的頁面,所呈現的搜尋網址,也不是所指向的https網域,以下的連結是,在google搜尋頁面中,所呈現的搜尋頁面。
https://www.google.com.tw/search?q=%E5%BE%88%E6%83%B3%E5%8E%BB%E9%9C%B2%E7%87%9F&ei=2WqXWu3lIoyY0gSG8aDQCw&start=10&sa=N&biw=1280&bih=572

搜尋頁面中,前5筆,是 https://www.gocamp.com.tw 這個網站中,正確的資訊內容。但...google頁面中,所呈現的網址,卻是跑80埠的vhost,而非443埠的正確網址。

煩請大大不吝指點,不知道在設定vhost中,那一個環節出錯,讓google把搜尋到的資訊連結網址,卻帶到其它非443的網域,感恩指正。

darkranger

  • 榮譽學長
  • 俺是博士!
  • *****
  • 文章數: 1382
    • 檢視個人資料
    • https://darkranger.no-ip.org
Re: nginx vhost 中 https 的設定問題
« 回覆 #3 於: 2018-03-01 21:29 »
非 https 的 vhost 做 port 443 重定向到 port 80 看看
由於重定向是建立原路徑的連線後才會發生
所以這不是一個有效的建議,真是抱歉

再看了一下整個狀況,我認為應該是因為你將 https://www.gocamp.com.tw 設定為 default_server 所致

keivn

  • 可愛的小學生
  • *
  • 文章數: 3
    • 檢視個人資料
Re: nginx vhost 中 https 的設定問題
« 回覆 #4 於: 2018-03-02 11:45 »
謝謝大大指導,目前己修正 default_server 的設定,就等待google的更新了。
感恩指導。