參考鏈接:https://blog.csdn.net/lorogy/article/details/104413315/
nginx.conf 文件
http {
include mime.types;
default_type application/octet-stream;
add_header X-Cache-Status $upstream_cache_status;
sendfile off;
keepalive_timeout 65;
# 項目1
server {
listen 8081;
server_name 192.168.1.88;
location / {
try_files $uri $uri/ /index.html;
root D:/xxx;
index index.html index.htm;
}
# 部署在同臺服務(wù)器的后端地址,跨域請求
location /bpi {
# rewrite實現(xiàn)url重寫以及重定向筹淫,去掉api慈俯,http://XX:8086/index
rewrite ^.+api/?(.*)$ /$1 break;
#include uwsgi_params;
proxy_pass http://XX:8086;
}
#第三方接口缭贡,跨域請求害淤,需要改打包的配置文件(如vue的打包配置)
# location /api/ {
# proxy_pass http://www.scis.net.cn/literature/;
# }
}
server {
listen 8082;
server_name 192.168.1.88;
location / {
try_files $uri $uri/ /index.html;
root D:/xxx;
index index.html index.htm;
}
}
server {
listen 80;
server_name 192.168.1.88;
# location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
# #禁止緩存唁影,每次都從服務(wù)器請求
# add_header Cache-Control no-store;
# }
# ^~ 開頭表示uri以某個常規(guī)字符串開頭方篮,不是正則匹配
location ^~/mhapp/ {
add_header Cache-Control no-cache;
add_header Cache-Control private;
expires -1s;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.88:8081/;
}
location ^~/web/ {
add_header Cache-Control no-cache;
add_header Cache-Control private;
expires -1s;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.88:8082/;
}
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}