nginx的HTTPS的配置
阿新 • • 發佈:2018-12-12
一、找到Nginx資料夾
二、openssl生成自簽名證書
-
openssl genrsa -out server.key 1024
-
openssl req -new -key server.key -out server.csr
-
cp server.key server.key.org
-
openssl rsa -in server.key.org -out server.key
-
openssl x509 -req -in server.csr -out server.crt -signkey server.key -days 3650
三、配置nginx:修改nginx.conf 檔案
server {
listen 443 ssl;
server_name static.jisuchou.com;
#server.crt和server.key都在nginx下面
ssl_certificate server.crt;
ssl_certificate_key server.key;
location / {
root (當前靜態檔案的路徑);
index index.html index.htm;
}
}
四、
將HTTP的80埠的請求重定向到HTTPS443埠來
server {
listen 80;
listen [::]:80;
server_name www.xxx.com;
return 301 https://$host$request_uri;
}