Nginx

Nginx新手試圖將http重定向到https

  • August 21, 2019

我讓我的 Nginx 測試伺服器在 Microsoft Azure 上的虛擬機上執行。http://www.myTestSite.com在我決定嘗試從 http 重定向到 https 之前,我能夠在訪問時查看我的網站。我按照本教程獲得了 Let’s Encrypt 證書,但現在http://www.myTestSite.com只是https://www.myTestSite.com超時。這是我的新default內容sites-available

server {
       listen 80;
       listen [::]:80;
       return 301 https://$host$request_uri;
}
server {
       listen 443 ssl default_server;
       listen [::]:443 default_server;
       root /var/www/html;
       index Main.html;
       server_name www.myTestSite.com;
       location / {
               try_files $uri $uri/ =404;
       }
       # pass PHP scripts to FastCGI server
       #
       location ~ \.php$ {
               include snippets/fastcgi-php.conf;
               fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
       #       # With php-cgi (or other tcp sockets):
       #       fastcgi_pass 127.0.0.1:9000;
       }
       ssl on;
       ssl_certificate /etc/letsencrypt/live/www.myTestSite.com/fullchain.pem; $
       ssl_certificate_key /etc/letsencrypt/live/www.myTestSite.com/privkey.pem$
}

我究竟做錯了什麼?

感謝大家的回复,但結果是我在嘗試打開埠 443 時搞砸了。對於源埠範圍,我輸入了 443,但我應該為所有內容輸入 *。

引用自:https://serverfault.com/questions/980133