【nginx正向代理配置】
对于http代理配置
server { resolver 8.8.8.8; listen 80; server_name localhost; root /usr/share/nginx/html; resolver_timeout 5s; location / { proxy_redirect off; proxy_pass http://$host$request_uri; #设定代理服务器的协议和地址 proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffers 256 4k; #配置缓存大小,关闭磁盘缓存读写减少I/O,以及代理连接超时时间。 proxy_max_temp_file_size 0k; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_next_upstream error timeout invalid_header http_502; proxy_cache_valid 200 302 10m; #配置代理服务器 Http 状态缓存时间。 proxy_cache_valid 301 1h; proxy_cache_valid any 1m; client_max_body_size 100m; } }
对于https的正向代理配置
server { resolver 8.8.8.8; listen 443; server_name localhost; root /usr/share/nginx/html; resolver_timeout 5s; location / { # 443使用 proxy_pass https://$http_host$request_uri; #设定代理服务器的协议和地址 proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffers 256 4k; proxy_max_temp_file_size 0k; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_next_upstream error timeout invalid_header http_502; } }