worker_processes 1;
events {
worker_connections 1024;
}
http {
client_max_body_size 100m;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
charset utf-8;
#项目一,同过ip:80直接访问
location / {
root /home/ruoyi-ui/dist; #dist文件的位置(根据自己dist包放置的位置决定)
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
#项目二,同过ip:80/project直接访问
location /project {
alias /home/zero/dist/;#注意第二个项目路径是alias不是root,通常最佳实际是配置一个项目的根root,其他的文件夹则使用alias,毕竟alias更加灵活
try_files $uri $uri/ /project/index.html;
index 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://10.10.11.79:8080/;
}
#第二个项目(前后端分离)反向代理来解决跨域问题,要与第二个项目vue里面跨域的配置一致,没有跨域问题可以不配置
location /zero-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://10.10.11.79:8083/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}