nginx配置文件

  1. 负载均衡
upstream sess {
    ip_hash;
    server backend1.example.com;
    server backend2.example.com;
}
server {
        listen 80;
        server_name www.session.com;
        location / {
                proxy_pass http://sess;
                proxy_set_header Host $http_host;
        }
}
  1. 反向代理 (服务器端做手脚)
server {
         listen 80;
         server_name  www.123.com;
 
         location / {
             proxy_pass http://127.0.0.1:8080;
             proxy_set_header Host $host; # 设置后端服务器接收到的Host头为原始请求的Host
             proxy_set_header X-Real-IP $remote_addr; # 设置X-Real-IP头为客户端的IP地址
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #用来表示HTTP请求端真实IP
             index  index.html index.htm index.jsp;

         }
     }
  1. 代理 客户端做手脚
posted on 2025-05-19 17:47  小二jerry  阅读(18)  评论(0)    收藏  举报