重点:域名必须备案;
nginx 相关配置
server {
listen 443 ssl;
server_name 域名;
ssl_certificate E://nginx-1.15.6/conf/pfx/xxx.crt;
ssl_certificate_key E://nginx-1.15.6/conf/pfx/xxx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#这里配置相当于直接把https(443)端口代理成了8100
location / {
proxy_pass http://localhost:8100;
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
}
}
# 若依后台相关配置 也可以参考上面多端口配置
server {
listen 8101;
server_name localhost;
# 将dist文件放到Nginx 的hml文件下(推荐)
location / {
root html/dapengdist;
index index.html;
try_files $uri $uri/ /index.html;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8100/;
}
# 下面的配置解决在某个界面重复刷新500的bug
error_page 500 502 503 504 404 400 /dapengdist/index.html;
location = /dapengdist/index.html {
root html;
}
}
正向代理 重写请求路径(rewrite)
主要配置逻辑
#如果你想将URL中的"abc"替换为"xyz",你可以使用以下代码:
location / {
rewrite ^(.*)abc(.*)$ $1xyz$2 break;
rewrite ^(.*)$ $1;
}
配置案例 443端口配置俩请求 location 第一个跟上面的配置相关联
server {
listen 443 ssl;
server_name 域名;
ssl_certificate xxx.crt;
ssl_certificate_key xxx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://localhost:8100;
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
}
#这里我是想把/1000去掉
#这个情况下 前端请求时baseUrl需要修改为这样:https:www.xxx.com:4399/1000
location /1000 {
proxy_pass 代理的域名端口号;
rewrite ^(.*)/1000(.*)$ $1$2 break;
rewrite ^(.*)$ $1;
}
}