nginx在絕大數(shù)的場景中我們使用其用于做web中間件或反向代理使用,但是nginx實(shí)際上也提供了正向代理的功能。下面我們來進(jìn)行nginx正向代理配置操作,以便大家能夠掌握nginx正向代理配置方法。
第一步:獲取nginx正向代理模塊
git clone
第二步:下載nginx源碼包
wget tar xf nginx-1.9.12.
第三步:通過補(bǔ)丁方法把上述下載的正向代理模塊導(dǎo)入到nginx模塊存儲目錄
cd nginx-1.9.12/ patch -p1 < /root/ngx_http_proxy_connect_module/patc
第四步:編譯安裝nginx
yum -y install openssl-devel zlib-devel prce-devel ./configure --add-dynamic-module=/root/ngx_http_proxy_connect_module make && make install
第五步:配置所允許通過代理主機(jī)的主機(jī)列表
cat /usr/local/nginx/con allow 127.0.0.1; allow 192.168.216.1; allow 192.168.216.185;
第六步:修改nginx配置文件
cat /usr/local/nginx/con user nobody; worker_processes 1; error_log log; error_log log notice; error_log log info; pid log; load_module /usr/local/nginx/module; #位置注意 events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log log main; sendfile on; tcp_nopush on; keepalive_timeout 0; keepalive_timeout 65; gzip on; server { listen 8080; #代理端口 resolver 119.29.29.29; #域名解析服務(wù)器 proxy_connect; proxy_connect_allow 443 563; proxy_connect_connect_timeout 10s; proxy_connect_read_timeout 10s; proxy_connect_send_timeout 10s; location / { proxy_pass http://$host; proxy_set_header Host $host; } include clien; #主機(jī)白名單 deny all; #除了主機(jī)白名單中的主機(jī),拒絕所有 error_page 404 ; redirect server error pages to the static page error_page 500 502 503 504 ; location = { root html; } proxy the PHP scripts to Apache listening on 127.0.0.1:80 location ~ \.php$ { proxy_pass ; } pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } deny access to .htaccess files, if Apache's document root concurs with nginx's one location ~ /\.ht { deny all; } } another virtual host using mix of IP-, name-, and port-based configuration server { listen 8000; listen somename:8080; server_name somename alias ano; location / { root html; index index.html index.htm; } } HTTPS server server { listen 443 ssl; server_name localhost; ssl_certificate cert.pem; ssl_certificate_key cert.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } } }
第七步:檢查并啟動nginx服務(wù)
/usr/local/nginx/sbin/nginx -t #檢查配置文件 /usr/local/nginx/sbin/nginx # 啟動服務(wù) /usr/local/nginx/sbin/nginx -s stop #關(guān)閉 /usr/local/nginx/sbin/nginx -s reload #重啟加載配置文件 ss -anput | grep ":8080" #檢查端口
第八步:被代理主機(jī)配置
第九步:被代理主機(jī)驗(yàn)證nginx正向代理可用性
ss -anput | grep ":8080" tcp LISTEN 0 128 *:8080 *:* users:(("nginx",pid=19515,fd=6),("nginx",pid=19514,fd=6)) tcp ESTAB 0 0 192.168.216.184:8080 192.168.216.185:35718 users:(("nginx",pid=19515,fd=11)) tcp ESTAB 0 0 192.168.216.184:8080 192.168.216.185:35712 users:(("nginx",pid=19515,fd=3))
建議關(guān)注收藏,沒事可以過來找找有用的文章哦。
1.《(如何設(shè)置代理服務(wù)器)edge如何設(shè)置代理服務(wù)器》援引自互聯(lián)網(wǎng),旨在傳遞更多網(wǎng)絡(luò)信息知識,僅代表作者本人觀點(diǎn),與本網(wǎng)站無關(guān),侵刪請聯(lián)系頁腳下方聯(lián)系方式。
2.《(如何設(shè)置代理服務(wù)器)edge如何設(shè)置代理服務(wù)器》僅供讀者參考,本網(wǎng)站未對該內(nèi)容進(jìn)行證實(shí),對其原創(chuàng)性、真實(shí)性、完整性、及時性不作任何保證。
3.文章轉(zhuǎn)載時請保留本站內(nèi)容來源地址,http://f99ss.com/keji/3210059.html