1、阿里雲申請免費的ssl服務
2、nginx配置
2.1、
2.2、
2.3、整體配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.xxx.com; #將localhost修改爲您證書綁定的域名,例如:www.example.com。
rewrite ^(.*)$ https://$host$1 permanent; #將所有http請求通過rewrite重定向到https。
location / {
index index.html index.htm;
}
}
# HTTPS server
# 以下屬性中以ssl開頭的屬性代表與證書配置有關,其他屬性請根據自己的需要進行配置。
server {
listen 443 ssl; #SSL協議訪問端口號爲443。此處如未添加ssl,可能會造成Nginx無法啓動。
server_name www.xxx.com; #將localhost修改爲您證書綁定的域名,例如:www.example.com。
root E:/atpdc/nginx-1.18.0/html;
index index.html index.htm;
ssl_certificate cert/www.xxx.com.pem; #將domain name.pem替換成您證書的文件名。
ssl_certificate_key cert/www.xxx.com.key; #將domain name.key替換成您證書的密鑰文件名。
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件。
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用該協議進行配置。
ssl_prefer_server_ciphers on;
location / {
root E:/atpdc/nginx-1.18.0/html_https; #站點目錄。
index index.html index.htm;
}
# 轉發tomcat端口
location ^~ /xxx{
proxy_pass http://127.0.0.1:8080/xxx;
}
}
}