https://cloud.tencent.com/document/product/619/12797
配置 Nginx 和 HTTPS
完成以上准備工作,就要開始配置 Nginx 和 HTTPS 了,首先需要申請一個 SSL 證書,可以到騰訊雲申請免費的 SSL 證書,申請成功之后下載證書,並把壓縮包中 Nginx 目錄下的證書文件通過 SFTP 上傳到服務器的 /data/release/nginx 目錄,如果沒有這個目錄則新建:

上傳完證書以后,可以開始配置 Nginx,進入服務器的 /etc/nginx/conf.d 目錄,新建一個 weapp.conf 文件,將文件拷貝到本地,打開編輯,寫入如下配置(請將配置里 wx.wafersolution.com 修改為你自己的域名,包括證書文件名):
請提前將域名解析到服務器的 IP 上
# 重定向 http 到 https server { listen 80; server_name wx.wafersolution.com; rewrite ^(.*)$ https://$server_name$1 permanent; } server { listen 443; server_name wx.wafersolution.com; ssl on; ssl_certificate /data/release/nginx/1_wx.wafersolution.com_bundle.crt; ssl_certificate_key /data/release/nginx/2_wx.wafersolution.com.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA; ssl_session_cache shared:SSL:50m; ssl_prefer_server_ciphers on; root /data/release/php-demo; location ~ \.php$ { root /data/release/php-demo; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /weapp/ { root /data/release/php-demo; index index.html index.htm index.php; try_files $uri $uri/ /index.php; } }
修改完將這個文件上傳到服務器上,然后在 ssh 中輸入:
nginx -t
如果顯示如下信息,則配置成功:

配置成功之后,輸入 nginx 回車,即可啟動 Nginx。
此時通過配置的域名訪問服務器,會顯示 404 Not Found,則表示配置成功:

