NGINX 反向代理

server {
    listen 80;
    server_name b.example.com;

    location / {
        # 代理到A网站,确保使用http://来指定协议
        proxy_pass http://a.example.com/;
        
        # 传递客户端的HTTP_REFERER头部
        proxy_set_header Referer $http_referer;
        
        # 传递客户端的真实IP地址
        proxy_set_header X-Real-IP $remote_addr;
        
        # 传递X-Forwarded-For头部,包含原始客户端IP地址
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
        # 传递Cookie头部,确保Session信息能够传递
        proxy_set_header Cookie $http_cookie;
        
        # 如果A网站使用HTTPS,你可能还需要配置SSL证书
        # ssl_certificate /path/to/cert.pem;
        # ssl_certificate_key /path/to/key.pem;
    }
}

上面保留 了HTTP_REFERER头部,IP,cookie

并使用HTTPS配置

保证了原网站的鉴权的存在的情况下实现反向代理。

 proxy_cache_path /data/cache/nginx levels=1:2 keys_zone=cache:10m max_size=10g inactive=60m use_temp_path=off;
#上面的在server外面

#下面的在server中
 # 启用缓存

            proxy_cache cache;

            # 设置缓存的有效时间
            proxy_cache_valid 200 302 10m;
            proxy_cache_valid 404 1m;

以上

发表回复