Nginx反向代理配置详解
发布时间:2026-04-20 18:18       
一、基础反向代理:upstream backend定义后端服务器组,location /配置proxy_pass http://backend转发请求,proxy_set_header Host设置原始Host头,proxy_set_header X-Real-IP设置客户端真实IP,proxy_set_header X-Forwarded-For传递代理链。二、WebSocket代理:proxy_set_header Upgrade设置Upgrade头,proxy_set_header Connection设置Connection upgrade,proxy_read_timeout延长超时时间。三、缓存配置:proxy_cache_path定义缓存目录和参数,proxy_cache启用缓存,proxy_cache_valid设置不同状态码的缓存时间,proxy_cache_key自定义缓存键。