Nginx不只能夠作反向代理,實現負載均衡。還能用做正向代理來進行上網等功能。nginx
正向代理:若是把局域網外的Internet想象成一個巨大的資源庫,則局域網中的客戶端要訪問Internet,則須要經過代理服務器來訪問,這種代理服務就稱爲正向代理服務器
server { resolver 114.114.114.114; resolver_timeout 10s; listen 8888; access_log /usr/local/nginx/logs/proxy-access.log main; error_log /usr/local/nginx/logs/proxy-error.log warn; location ~ / { proxy_pass http://$http_host$request_uri; proxy_set_header HOST $http_host; 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; } }
測試: # curl -l --proxy 127.0.0.1:8888 "www.baidu.com"負載均衡