Nginx
生成证书域名
1. ohttps
已测可用
2. acme.sh
未搞懂
部署vue项目
Vue项目目录:C:\website\dataPreview
部署带别名的vue项目
配置Vue项目vue.config.js
module.exports = {
publicPath: '/dataPreview',
}
配置Nginx
location /dataPreview {
alias C:\website\dataPreview;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
部署不带别名的vue项目
配置Vue项目vue.config.js
module.exports = {
publicPath: './',
}
配置Nginx
server {
listen 80;
server_name localhost;
location / {
root C:/website/front; # 前端文件夹路径,front是vue项目打包后的文件夹名
try_files $uri $uri/ /index.html break;
}
}
同时监听80和443
server {
listen 80;
listen 443 ssl;
server_name localhost;
ssl_certificate ../cert/cert.cer; # windows https 证书文件路径
ssl_certificate_key ../cert/cert.key; # windows https 证书文件路径
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# 如果当前访问的不是https请求,则自动转发到https请求上
if ($server_port !~ 443) {
rewrite ^(.*)$ https://$host$1 permanent;
}
# 符合匹配条件的本地文件
location ~ ^/MP_verify_.*.txt$ {
root C:\file; # 匹配文件
rewrite ^(.*)$ \$1 break;
}
# 后台应用
location /wxpush {
proxy_redirect off;
# 修改转发请求头,让proxy_pass代理的端口的应用可以收到真实的请求
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 客户端真实协议(http/https)
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8080/demo; # 转发规则
}
# vue项目
location / {
root C:\website\front;
try_files $uri $uri/ /index.html break;
}
}
80与443分开写
server {
listen 80;
server_name localhost;
if ($server_port !~ 443) {
rewrite ^(.*)$ https://$host$1 permanent;
}
}
#server {
listen 443 ssl;
server_name localhost;
ssl_certificate ../cert/cert.cer; # windows https 证书文件路径
ssl_certificate_key ../cert/cert.key; # windows https 证书文件路径
ssl on;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# vue项目
location / {
root C:\website\front;
try_files $uri $uri/ /index.html break;
}
#}