Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx do forward proxy configuration

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Nginx is used for web middleware or reverse proxy in most scenarios, but nginx actually provides the function of forward proxy. Let's do the nginx forward proxy configuration operation so that you can master the nginx forward proxy configuration method.

Step 1: get the nginx forward proxy module

# git clone https://github.com/chobits/ngx_http_proxy_connect_module

Step 2: download the nginx source code package

# wget http://nginx.org/download/nginx-1.9.12.tar.gz

# tar xf nginx-1.9.12.tar.gz

Step 3: import the downloaded forward proxy module into the nginx module storage directory through the patch method

# 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 http://$host; 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 http://127.0.0.1; #} # 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" # 检查端口 第八步:被代理主机配置

Step 9: the proxied host verifies the availability of nginx forward agent

# ss-anput | grep ": 8080"

Tcp LISTEN 0128 *: 8080 *: * users: ("nginx", pid=19515,fd=6), ("nginx", pid=19514,fd=6))

Tcp ESTAB 0 0 192.168.216.184 users 8080 192.168.216.185 tcp ESTAB 35718 (("nginx", pid=19515,fd=11))

Tcp ESTAB 0 192.168.216.184tcp ESTAB 8080 192.168.216.185tcp ESTAB 35712 users: ("nginx", pid=19515,fd=3)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report