Home >Operation and Maintenance >Nginx >How to use Nginx proxy to access the Internet
http proxy configuration
# 正向代理上网 server { listen 38080; # 解析域名 resolver 8.8.8.8; location / { proxy_pass $scheme://$http_host$request_uri; } }
Configure the proxy ip and port in the browser, and then visit http://www.ip138.com. You can find that the ip has changed. The description is effective
However, the https website cannot be opened. This is because native nginx only supports http forward proxy. In order for nginx to support https forward proxy, you can apply the ngx_http_proxy_connect_module patch. SSL module support
Add https proxy module
You need to recompile nginx here. You need to check the current nginx version and compilation options, and then go to the official website to download the same version of nginx source code and recompile
/usr/local/nginx/sbin/nginx -v
wget http://nginx.org/download/nginx-1.15.12.tar.gz tar -zxvf nginx-1.15.12.tar.gz
Download the module ngx_http_proxy_connect_module
git clone https://github.com/chobits/ngx_http_proxy_connect_module
Patch and modify the nginx source code. This step is very important, otherwise the subsequent make will not pass.
patch -d /root/nginx-1.15.12/ -p 1 < /root/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite
Add the module after the original configuration, pay attention after making Do not install
cd /root/nginx-1.15.12/ ./configure --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module --add-module=/root/ngx_http_proxy_connect_module/ make mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak cp /root/nginx-1.15.12/objs/nginx /usr/local/nginx/sbin/
Change the configuration file as follows, and then start the service
# 正向代理上网 server { listen 38080; # 解析域名 resolver 8.8.8.8; # ngx_http_proxy_connect_module 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 $scheme://$http_host$request_uri; } }
The above is the detailed content of How to use Nginx proxy to access the Internet. For more information, please follow other related articles on the PHP Chinese website!