server { listen 80; server_name www.baidu.com; location / { proxy_pass http://1.2.3.4; //後端ip地址 proxy_redirect off; //關閉後端返回的header修改 proxy_set_header Host $host; //修改發送到後端的header的host proxy_set_header X-Real-IP $remote_addr; //設置真實ip proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
nginx配置反向代理很簡單,只需要在nginx.conf配置文件加入server區塊。