WordPress系列教程(六)----域名開啟https連線
阿新 • • 發佈:2018-12-11
一、前言
現在基本上網站都會使用https進行訪問,建立一個資訊保安通道,來保證資料傳輸的安全。
二、域名配置
在域名資訊頁中點選免費開啟SSL證書功能
開啟之後,在阿里雲中找到雲盾
找到證書一欄
找到相應的容器進行下載
三、配置證書
首先在Nginx目錄下建立cert/資料夾,比如我這裡就是/usr/local/nginx/cert目錄,將壓縮包中的兩個檔案上傳到該目錄下,修改nginx.conf配置檔案為如下所示:
user www www; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; keepalive_timeout 65; # # HTTPS server # server { listen 443 ssl; server_name localhost; root /xxx/xxx/xxx/xxx; ssl_certificate ../cert/1538361029435.pem; ssl_certificate_key ../cert/1538361029435.key; ssl_stapling on; ssl_stapling_verify on; error_page 404 /404.html; location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~* .(jpg|gif|png|js|css|svg)$ { root /xxx/xxx/xxx/xxx; if (-f $request_filename) { expires max; break; } } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; 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; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; } } server { listen 80; server_name localhost; rewrite ^ https://$host$request_uri? permanent; } }
在nginx配置檔案中,把原來server塊中的80埠(http訪問)的語句改為443埠,並引入SSL各項配置,同時啟用HSTS(HTTP嚴格傳輸安全),然後重啟服務:
/usr/local/nginx/sbin/nginx -s reload