在nginx/conf目录下新建conf.d文件夹
nginx/conf/ngxin.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#重点指定文件夹
include D:/nginx/conf/conf.d/*.conf;
}
未测试域名部署,显示是通过两个端口号对应到两.conf文件
server {
listen 8083;
server_name localhost;
#访问前缀 dh 完整路径: ip:8083/dh/
#alias D:/vue/dh/; 需要新建dh文件夹然后把打包后的dist文件夹中的内容放到dh文件夹里
# try_files $uri $uri/ /dh/index.html; 指向刷新的地址
location /dh/ {
index index.html index.htm;
alias D:/vue/dh/;
try_files $uri $uri/ /dh/index.html;
}
#代理后端接口 和 listen 8083 没有关系
location /prod-api {
rewrite ^.+prod-api/?(.*)$ /$1 break;
proxy_pass http://127.0.0.1:8089;
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;
}
location /pingmeiyikuang/ {
index index.html index.htm;
alias D:/nginx/html/pingmeiyikuang/;
try_files $uri $uri/ @router;
}
location /pingmeiyikuang-api {
rewrite ^.+pingmeiyikuang-api/?(.*)$ /$1 break;
proxy_pass http://127.0.0.1:8081;
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;
}
location @router {
rewrite ^.*$ /index.html last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}