server {
// 监听的端口,代理后,前端访问输入的端口
listen 9090;
#listen [::]:80 default_server ipv6only=on;
server_name localhost;
// root根路径,nginx部署后放置的前台打包后dist里的文件的静态目录
location / {
root /home/ruoyi/projects/ruoyi-ui;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
// proxy_pass /prod-api/是生产环境 后台服务地址例如:http://localhost:8080/
location /prod-api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass 后台地址;
client_max_body_size 100m;
}
// proxy_pass /dev-api/是开发环境 /dev-api/是vite.config.js里写的server里proxy ' /dev-api' 后台服务地址例如:http://localhost:8080/
location /dev-api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass 后台地址;
client_max_body_size 100m;
}
}