| 1234567891011121314151617181920212223242526272829303132333435363738 |
- # nginx.conf
- worker_processes 5;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- client_max_body_size 200m;
- sendfile on;
- keepalive_timeout 65;
- server {
- listen 80; # 容器内端口
- server_name localhost;
- # 前端静态资源目录(对应容器内的 /usr/share/nginx/html)
- root /usr/share/nginx/html;
- index index.html;
- # 关键:处理 VUE Router history 模式(避免刷新 404)
- location / {
- try_files $uri $uri/ /index.html; # 所有路由指向 index.html
- }
- # 关键:反向代理 API(解决跨域,替换为你的真实后端地址)
- location /prod-api/ {
- proxy_pass http://192.168.58.159:7772/; # 后端 API 地址(末尾加 / 避免路径拼接问题)
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme; # 传递 HTTPS 协议
- }
- }
- }
|