如何在nginx 服務器上配置https協議
一、騰訊雲購買的SSL證書
步驟1、
購買SSL證書 ,可購買免費版的,當狀態為已頒發之后 下載證書
步驟2、
在站點服務器上開啟443端口(這點很重要)
步驟3、
配置nginx.conf文件
server { #SSL 訪問端口號為 443 listen 443 ssl; #填寫綁定證書的域名 server_name www.xxx.com; #證書文件名稱 ssl_certificate /etc/nginx/1_www.antheamlhotel.com_bundle.crt; #私鑰文件名稱 ssl_certificate_key /etc/nginx/2_www.antheamlhotel.com.key; ssl_session_timeout 5m; #請按照以下協議配置 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #請按照以下套件配置,配置加密套件,寫法遵循 openssl 標准。 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; root /data/meilan; index index.php index.html index.htm; try_files $uri $uri/ @rewrite; location @rewrite { rewrite ^/(.*)$ /index.php?_url=/$1; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { } location ~ /\.ht { deny all; } #禁止訪問的文件或目錄 location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) { return 404; } }
server{
listen 80;
server_name www.xxx.com;
#把http的域名請求轉成https
return 301 https://$host$request_uri;
}
結束