去百度云或者阿里云下载ssl证书(免费1年有效期)
内容为俩个文件(pem 和 key)
上传至服务器
找到配置文件
打开以下注释 SSL configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate /nvmjs/nginx-ssl/www.nvmjs.com.pem;
ssl_certificate_key /nvmjs/nginx-ssl/www.nvmjs.com.key;
# 根目录 configuration
#
root /nvmjs/nvmjs-dist/dist;
index index.html index.htm index.nginx-debian.html;
server_name _;
client_max_body_size 1000m;
location / {
if (!-f $request_filename) {
rewrite ^/ /index.html break;
}
}
# 反向代理 configuration
#
location /api/ {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:7001;
}
}
重启nginx
目前支持http 和 https
果如需要 http 转 https 访问
配置文件server 分成2个 通过 rewrite ^(.*)host$1 permanent;
server {
listen 80 default_server;
listen [::]:80 default_server;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate /nvmjs/nginx-ssl/www.nvmjs.com.pem;
ssl_certificate_key /nvmjs/nginx-ssl/www.nvmjs.com.key;
# 根目录 configuration
#
root /nvmjs/nvmjs-dist/dist;
index index.html index.htm index.nginx-debian.html;
server_name _;
client_max_body_size 1000m;
location / {
if (!-f $request_filename) {
rewrite ^/ /index.html break;
}
}
# 反向代理 configuration
#
location /api/ {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:7001;
}
}