nginx 做正向代理配置
nginx在絕大數的場景中我們使用其用於做web中介軟體或反向代理使用,但是nginx實際上也提供了正向代理的功能。下面我們來進行nginx正向代理配置操作,以便大家能夠掌握nginx正向代理配置方法。
第一步:獲取nginx 正向代理模組
# git clone
第二步:下載nginx 原始碼包
# wget
# tar xf nginx-1.9.12.tar.gz
第三步:透過補丁方法把上述下載的正向代理模組匯入到nginx 模組儲存目錄
# cd nginx-1.9.12/
# patch -p1 < /root/ngx_http_proxy_connect_module/patch/proxy_connect.patch
第四步:編譯安裝nginx
# yum -y install openssl-devel zlib-devel prce-devel
# ./configure --add-dynamic-module=/root/ngx_http_proxy_connect_module
# make && make install
第五步:配置所允許透過代理主機的主機列表
# cat /usr/local/nginx/conf/client-allow.conf
allow 127.0.0.1;
allow 192.168.216.1;
allow 192.168.216.185;
第六步:修改nginx 配置檔案
# cat /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
load_module /usr/local/nginx/modules/ngx_http_proxy_connect_module.so; # 位置注意
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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8080; # 代理埠
resolver 119.29.29.29; # 域名解析伺服器
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
proxy_set_header Host $host;
}
include client-allow.conf; # 主機白名單
deny all; # 除了主機白名單中的主機,拒絕所有
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
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 another.alias;
# 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 服務
# /usr/local/nginx/sbin/nginx -t # 檢查配置檔案
# /usr/local/nginx/sbin/nginx # 啟動服務
# /usr/local/nginx/sbin/nginx -s stop # 關閉
# /usr/local/nginx/sbin/nginx -s reload # 重啟載入配置檔案
# ss -anput | grep ":8080" # 檢查埠
第八步:被代理主機配置
第九步:被代理主機驗證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))
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30345407/viewspace-2689867/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Nginx之路--配置正向代理、反向代理Nginx
- Nginx正向代理和反向代理配置Nginx
- nginx正向代理、反向代理Nginx
- nginx做正向代理(Centos7,支援http和https)NginxCentOSHTTP
- Nginx配置正向代理支援HTTP和HTTPS轉發NginxHTTP
- Nginx-正向代理實現Nginx
- Nginx 學習系列(一) ------------- 正向代理與反向代理Nginx
- 正向代理與反向代理的區別【Nginx讀書筆記】Nginx筆記
- nginx 反向代理做域名轉發簡單配置Nginx
- nginx代理配置Nginx
- nginx正向代理訪問百度地圖APINginx地圖API
- 正向代理與反向代理
- 反向代理與正向代理
- 正向代理和反向代理
- 【代理】正向代理、反向代理、透明代理
- Nginx 配置:反向代理Nginx
- Nginx 配置反向代理Nginx
- nginx做代理IP埠轉發的安裝和部署配置Nginx
- 反向代理和正向代理區別
- 正向代理與反向代理總結
- 圖解正向代理與反向代理圖解
- Nginx多層代理配置Nginx
- 圖解正向代理、反向代理、透明代理圖解
- Nginx 教程二:利用nginx搭建靜態檔案服務、正向代理伺服器、反向代理伺服器Nginx伺服器
- 正向代理和反向代理的形象理解
- 反向代理與正向代理差異分析
- 什麼是正向代理和反向代理?
- 圖文總結:正向代理與反向代理
- nginx反向代理配置去除字首Nginx
- tomcat 配置nginx 反向代理TomcatNginx
- 配置Nginx反向代理TomcatNginxTomcat
- Nginx專題(1):Nginx之反向代理及配置Nginx
- yapi 的 nginx 反向代理配置文字APINginx
- nginx反向代理配置如何去除字首Nginx
- 淺析正向代理與反向代理 海外代理IP介紹
- 什麼是反向代理,什麼又是正向代理?
- 正向代理和反向代理的本質區別
- 什麼是正向代理?什麼是反向代理?