伺服器ssl證書安裝
想給伺服器安裝個ssl證書,折騰了小半天,終於搞好了,不過也是踩了坑的。現在分享出來給大家。
填好申請域名及相應的資訊後,下載他們的csr生成器,長這樣
點選建立csr後,申請,會生成.csr檔案和.key檔案,然後將生成的csr貼上到網頁中相對應的位置,
然後一步步申請,最後將申請好的證書下載下來
這下你就有三個檔案了,一個是.csr一個是.key還有就是下載下來的證書,將證書和私鑰放在伺服器相應的資料夾下,然後配置站點
server { listen 80; server_name 域名; rewrite ^(.*) https://$server_name$1 permanent; } server { listen 443 ssl; server_name 域名; ssl on; ssl_certificate /etc/nginx/vhost/aaa.crt; #證書公鑰位置 ssl_certificate_key /etc/nginx/vhost/aaa.key; #證書私鑰位置 ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL; ssl_prefer_server_ciphers on;
root 目錄; index index.php index.html index.htm;
location / { # 這裡使用try_files進行url重寫,不用rewrite了。 try_files $uri $uri/ /index.php?$query_string; }
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 SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
location ~ /\.ht { deny all; } }
申請過程中,注意生成的私鑰只有第一次和證書是唯一對應的,其餘的都是不對應的。只有重新申請!