antd design pro 配置了多个代理时,本地服务能正常访问
devServer: {
proxy: [
{
context: ['/api', '/auth', '/equ', '/project', '/mon'],
target: 'localhost:8082',
changeOrigin: true,
},
],
},
发布到nginx服务器时,nginx.conf 文件需增加代理配置
// nginx.conf 文件配置添加
location ^~/api/ {
proxy_pass http://localhost:8082; #要转发的地址
proxy_cookie_path / /;
}
location ^~/auth/ {
proxy_pass http://localhost:8082; #要转发的地址
proxy_cookie_path / /;
}
location ^~/equ/ {
proxy_pass http://localhost:8082; #要转发的地址
proxy_cookie_path / /;
}
location ^~/project/ {
proxy_pass http://localhost:8082; #要转发的地址
proxy_cookie_path / /;
}
location ^~/mon/ {
proxy_pass http://localhost:8082; #要转发的地址
proxy_cookie_path / /;
}
在服务配置中添加 try_files $uri $uri/ /index.html;
页面可正常刷新,不会出现404页面
server {
listen 8090;
server_name localhost;
location / {
root html/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}