阿里云申请 SSL
控制台,找到 SSL 证书菜单,购买“免费版个人 DV”,按照提示把 SSL 证书设置到对应的域名。
把 SSL 证书上传到 nginx 目录
先把 SSL 证书从阿里云控制台下载下来,服务器上新建目录 /etc/nginx/cert, 把证书文件上传到 /etc/nginx/cert。
设置 nginx.conf 如下:
user root;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;# Load dynamic modules. See /usr/share/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;events {worker_connections 1024;}http {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 /var/log/nginx/access.log main;sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 65;types_hash_max_size 2048;include /etc/nginx/mime.types;default_type application/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;upstream my_nodejs_upstream {server 127.0.0.1:3001;keepalive 64;}server {listen 80;server_name wx.huizhanyt.com;location / {proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $http_host;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_pass http://my_nodejs_upstream/;proxy_redirect off;proxy_read_timeout 240s;}}server {listen 443 ssl;server_name wx.huizhanyt.com;ssl_certificate cert/wx.huizhanyt.com.pem; #将domain name.pem替换成您证书的文件名。ssl_certificate_key cert/wx.huizhanyt.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 / {proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $http_host;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_pass http://my_nodejs_upstream/;proxy_redirect off;proxy_read_timeout 240s;}}}
用 sudo nginx -t 检查配置是否有错误。
重启 nginx
firewallD 添加 https 服务
firewall-cmd —permanent —add-service=https
