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

Mini Program Custom TabBar Component Encapsulation

This article example shares the specific code for...

Vue implements page caching function

This article example shares the specific code of ...

Analysis of CocosCreator's new resource management system

Table of contents 1. Resources and Construction 1...

B2C website user experience detail design reference

Recently, when using Apple.com/Ebay.com/Amazon.co...

How to solve the slow speed of MySQL Like fuzzy query

Question: Although the index has been created, wh...

HTML form component example code

HTML forms are used to collect different types of...

Specific use of nginx keepalive

The default request header of the http1.1 protoco...

How to convert mysql bin-log log files to sql files

View mysqlbinlog version mysqlbinlog -V [--versio...

The latest MySQL 5.7.23 installation and configuration graphic tutorial

The detailed installation and configuration of th...

What you need to know about filters in Vue

Table of contents Preface What is a filter How to...

XHTML introductory tutorial: text formatting and special characters

<br />This section introduces how to impleme...

JavaScript microtasks and macrotasks explained

Preface: js is a single-threaded language, so it ...

Why MySQL should avoid large transactions and how to solve them

What is a big deal? Transactions that run for a l...