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 configure forward proxy to support HTTP and HTTPS forwarding

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

Share

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

1. Nginx does not support https. If you want to use it, you need to install the following patch.

Reference documentation:

Https nginx patch

Https://github.com/chobits/ngx_http_proxy_connect_module

Install the compilation environment and tools

Yum install gcc gcc-c++ autoconf automake-y

Yum install pcre pcre-devel-y

Yum install openssl openssl-devel-y

Yum install patch-y

Yum install git-y

Yum install net-tools-y

Install Nginx and ngx_http_proxy_connect_module modul

Mkdir-p / downloads

Cd / downloads

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

Wget http://nginx.org/download/nginx-1.15.12.tar.gz

Tar-xzvf nginx-1.15.12.tar.gz

Cd nginx-1.15.12/

Patch-p1 < / downloads/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch

. / configure-- add-module=/downloads/ngx_http_proxy_connect_module

Make & & make install

Modify Nginx configuration file

Nginx directory: / usr/local/nginx

Modify the conf/nginx.conf configuration file in the Nginx directory and add the following to http:

Server {

Resolver 114.114.114.114

Listen 8080

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

}

}

Server {

Listen 8443

# dns resolver used by forward proxying

Resolver 114.114.114.114

# forward proxy for CONNECT request

Proxy_connect

Proxy_connect_allow 443 563

Proxy_connect_connect_timeout 10s

Proxy_connect_read_timeout 10s

Proxy_connect_send_timeout 10s

# forward proxy for non-CONNECT request

Location / {

Proxy_pass http://$host;

Proxy_set_header Host $host

}

}

Start Nginx

Run. / sbin/nginx to start Nginx.

Nginx Command reference:

# Start Nginx

. / sbin/nginx

# Reload Nginx configuration

. / sbin/nginx-s reload

# Stop Nginx

. / sbin/nginx-s stop

View Port

Netstat-tnlp | grep 8080

Netstat-tnlp | grep 8443

Turn on the firewall

Firewall-cmd-zone=public-add-port=8080/tcp

Firewall-cmd-zone=public-add-port=8080/tcp-permanent

Firewall-cmd-zone=public-add-port=8443/tcp

Firewall-cmd-zone=public-add-port=8443/tcp-permanent

Firewall-cmd-reload

one

Test agent

# Test HTTP proxy

Curl-- proxy 192.168.87.123 http://www.baidu.com

# Test HTTPS proxy

Curl-- proxy 192.168.87.123 https://www.baidu.com

The client needs to set up a proxy

Export http_proxy= "http://192.168.87.123:8080"

Export https_proxy= "http://192.168.87.123:8443"

If it is permanent, it needs to be written in the / etc/profile file.

Source / etc/pofile to take effect

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