History 模式配置
server
{
listen 80;
server_name 域名/外网IP;
index index.html;
root /home/wwwroot/eladmin/dist; #dist上传的路径
# 避免访问出现 404 错误
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
## 后端接口配置
location ^~ /api/ {
proxy_pass http://你的ip:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Hash 模式配置
server {
listen 80;
server_name 域名/外网IP;
location / {
root /home/wwwroot/eladmin/dist; #dist上传的路径
index index.html;
}
## 后端接口配置
location ^~ /api/ {
proxy_pass http://你的ip:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}