server {
listen 80;
server_name your-domain.com;
location / {
root /path/to/your/vue-app/dist;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://your-backend-server; # 假设你的后端API服务器地址
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
nginx 配置如上,由于我的vite.config.js文件中配置的路径是 /api,nginx配置的是 /api/ 去掉后面的/就可以访问成功了