## Nginx 反向代理主要负责静态文件处理和负载均衡,直接复制下面的配置。 - `proxy_pass` 为 Gin 服务器的监听端口 ~~~ server { server_name www.domain.com; listen 80; root /data/mix/public; location / { proxy_http_version 1.1; proxy_set_header Connection "keep-alive"; proxy_set_header Host $http_host; proxy_set_header Scheme $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; if (!-f $request_filename) { proxy_pass http://127.0.0.1:8080; } } } ~~~ >[info] 在代码中通过读取 `c.Request.Header.Get("X-Real-IP")` 或者 `c.Request.Header.Get("X-Forwarded-For")` 来获取客户端的真实 IP