Home > Operation and Maintenance > Nginx > How to use Nginx proxy to access the Internet

How to use Nginx proxy to access the Internet

PHPz
Release: 2023-05-22 19:35:18
forward
2075 people have browsed it

http proxy configuration

# 正向代理上网
server {
  listen    38080;

  # 解析域名
  resolver   8.8.8.8;

  location / {
    proxy_pass $scheme://$http_host$request_uri;
  }
}
Copy after login

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
Copy after login
wget http://nginx.org/download/nginx-1.15.12.tar.gz
tar -zxvf nginx-1.15.12.tar.gz
Copy after login

Download the module ngx_http_proxy_connect_module

git clone https://github.com/chobits/ngx_http_proxy_connect_module
Copy after login

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
Copy after login

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/
Copy after login

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;
  }
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template