How to use Nginx proxy to surf the Internet

How to use Nginx proxy to surf the Internet

I usually use nginx as a reverse proxy for tomcat and other applications. In fact, nginx also supports forward proxy

The so-called forward proxy is that the intranet users access external resources through the gateway, that is, when the computer is surfing the Internet, the browser is set to access the Internet through the http proxy address.

Reverse proxy is when external users access intranet resources through a gateway. In layman's terms, your website runs on port 8080 of the intranet, and others can access it through port 80.

http proxy configuration

# Forward proxy Internet access server {
  listen 38080;

  # Resolve the domain name resolver 8.8.8.8;

  location / {
    proxy_pass $scheme://$http_host$request_uri;
  }
}

Configure the proxy IP and port in the browser, then visit http://www.ip138.com, and you will find that the IP has changed, indicating that the proxy has taken effect.

However, the https website cannot be opened. This is because the native nginx only supports http forward proxy. In order to support https forward proxy for nginx, you can install 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 for recompilation.

/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 module ngx_http_proxy_connect_module

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

Apply the 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 modules after the original configuration, and be careful not to install after make

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 start the service

# Forward proxy Internet access server {
  listen 38080;

  # Resolve the domain name 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;
  }
}

Summarize

The proxy seems to be not very stable and sometimes cannot be opened, especially https websites. Don't do this when visiting foreign websites. This is just to familiarize yourself with the forward proxy function of nginx.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to use environment variables in nginx configuration file
  • How to implement distributed current limiting using nginx
  • How to deploy static pages using Nginx
  • Detailed explanation of how to build a CDN server with Nginx (picture and text)
  • Nginx working mode and proxy configuration usage details

<<:  How to use and limit props in react

>>:  Take you to understand MySQL character set settings in 5 minutes

Recommend

Detailed explanation of React setState data update mechanism

Table of contents Why use setState Usage of setSt...

Example of Vue routing listening to dynamically load the same page

Table of contents Scenario Analysis Development S...

Tutorial on installing DAMO database on Centos7

1. Preparation After installing the Linux operati...

Brief analysis of the various versions of mysql.data.dll driver

Here is the mysql driver mysql.data.dll Notice: T...

How does Vue3's dynamic components work?

Table of contents 1. Component Registration 1.1 G...

Using jQuery to implement the carousel effect

What I bring to you today is to use jQuery to imp...

MySQL 8.0.18 installation and configuration graphic tutorial

Learning objectives: Learn to use Windows system ...

Detailed installation process and basic usage of MySQL under Windows

Table of contents 1. Download MySQL 2. Install My...

Detailed explanation of how to use $props, $attrs and $listeners in Vue

Table of contents background 1. Document Descript...

MySQL uses variables to implement various sorting

Core code -- Below I will demonstrate the impleme...

Nginx configuration based on multiple domain names, ports, IP virtual hosts

1. Type introduction 1.1 Domain-based virtual hos...