1,申请SSL证书。
2,配置nginx.conf监听443端口,443是ssl默认的端口
http { server {listen 80 default_server;listen [::]:80 default_server;server_name _;rewrite ^(.*)$ https://$host$1 permanent; #把http的域名请求转成https}server {listen 443 ssl http2 default_server;listen [::]:443 ssl http2 default_server;server_name _; root /usr/share/nginx/html; #web文件ssl_certificate cert/3760280_www.honghh.top.pem;#改成你的证书的名字ssl_certificate_key cert/3760280_www.honghh.top.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 / {try_files $uri $uri/ @router;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404index index.html index.htm;}#对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件#因此需要rewrite到index.html中,然后交给路由在处理请求资源location @router {rewrite ^.*$ /index.html last;}location /prod-api/ {# rewrite ^/prod-api/(.*)$ /$1 break; proxy_pass http://localhost:8088/;}error_page 404 /404.html;location = /40x.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}}
3,到云服务器的控制台,添加安全组规则,增加443端口
4,云服务器的防火墙开启443端口
# 增加443端口firewall-cmd --zone=public --add-port=443/tcp --permanent# 重启防火墙firewall-cmd --reload