gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
写一个nginx配置,前端访问auction.smilelifeshop.cn,项目目录是/projects/aisuite/auction_front/friend-shop-…
- User
写一个nginx配置,前端访问auction.smilelifeshop.cn,项目目录是/projects/aisuite/auction_front/friend-shop-admin/dist/,后端是5001端口,比如:http://47.116.189.51:5001/api/login
- Assistant
要配置一个 Nginx 服务器,以便在访问
auction.smilelifeshop.cn时提供静态文件,同时将 API 请求转发到后端服务(5001端口),你可以使用以下配置示例:server { listen 80; server_name auction.smilelifeshop.cn; # 前端静态文件配置 location / { root /projects/aisuite/auction_front/friend-shop-admin/dist/; index index.html index.htm; try_files $uri $uri/ /index.html; # 处理单页面应用的路由 } # 后端 API 转发 location /api/ { proxy_pass http://47.116.189.51:5001/; # 将请求转发到后端 API proxy_set_header Host $host; # 保留原始主机头 proxy_set_header X-Real-IP $remote_addr; # 保留真实客户端 IP proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 保留转发链 proxy_set_header X-Forwarded-Proto $scheme; # 保留原始协议 (http/https) } }说明:
- listen 80; : 此配置指定 Nginx 在 80 端口上监听 HTTP 请求。
- server_name auction.smilelifeshop.cn; : 指定服务器名称为
auction.smilelifeshop.cn。 - : 此块处理根路径请求,提供静态文件。