Implementation of Nginx Intranet Standalone Reverse Proxy

Implementation of Nginx Intranet Standalone Reverse Proxy

Nginx Intranet Standalone Reverse Proxy

Ubuntu18.04 virtual machine 1 IP: 192.168.10.10
Ubuntu18.04 virtual machine 2 IP: 192.168.10.11

Test purpose: Deploy Nginx server on virtual machine 1 (192.168.10.10:80), access the self-set domain name through the browser, and reverse proxy to the intranet virtual machine 2 (192.168.10.11:1234).

It is best that virtual machine 2 can be accessed with a browser, and the display interface is different from Nginx, such as installing a tomcat.

1 Nginx Installation

Virtual machine 1 is used as the Nginx server and is installed as follows:

sudo apt-get install build-essential
sudo apt-get install libtool
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install openssl
sudo apt-get update
sudo apt-get install nginx

Run the systemctl status nginx command to verify whether the installation is successful.

$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
   Active: active (running) since Mon 2021-11-01 10:07:38 CST; 4h 19min ago
     Docs: man:nginx(8)
 Main PID: 8915 (nginx)
    Tasks: 3 (limit: 9461)
   CGroup: /system.slice/nginx.service
           ├─8915 nginx: master process /usr/sbin/nginx -g daemon on; master_pro
           ├─8916 nginx: worker process
           └─8917 nginx: worker process
...

2 Configure Nginx

Virtual Machine 1:

/etc/nginx/nginx.conf is the main configuration file. I haven't studied it in detail, but be sure to uncomment the following content:

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

After modification, restart Nginx with service nginx restart.

Create /etc/nginx/conf.d/test.conf as follows:

server {
  listen 80; #Nginx server listening port charset utf-8;
  server_name test.com; #Domain name location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Nginx-Proxy true;

    proxy_pass http://192.168.10.11:1234/; #reverse proxy IP+port proxy_redirect off;
  }
}

In the proxy_pass http://192.168.10.10:1234/; line, don’t forget to add the final slash ‘/’.

nginx -s reload updates the configuration

The principle of reload:
1 First check whether the configuration syntax is correct
2 The main process tries to apply the configuration
3 If successful: start a new worker process and close the old one
4 If failed: main process configuration rollback

3 Modify the hosts file

Virtual machine 1 adds the following to the /etc/hosts file:

192.168.10.10 test.com

4 Testing

Enter 192.168.10.10 in the browser, and the text of Nginx is displayed. This is the Nginx effect of virtual machine 1 itself.

When you enter test.com, the application content of virtual machine 2 appears, indicating that the reverse proxy is successful.

This is the end of this article about the implementation of Nginx intranet stand-alone reverse proxy. For more relevant Nginx intranet reverse proxy content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Nginx reverse proxy solves cross-domain problems in various situations
  • Nginx routing forwarding and reverse proxy location configuration implementation
  • Nginx reverse proxy learning example tutorial
  • Getting Started with Nginx Reverse Proxy
  • nginx reverse proxy and detailed usage

<<:  JavaScript BOM location object + navigator object + history object

>>:  Solution to inserting a form with a blank line above and below

Recommend

MySQL integrity constraints definition and example tutorial

Table of contents Integrity constraints Definitio...

How to create a stored procedure in MySQL and add records in a loop

This article uses an example to describe how to c...

Implementation steps for installing Redis container in Docker

Table of contents Install Redis on Docker 1. Find...

9 Tips for Web Page Layout

<br />Related articles: 9 practical suggesti...

How to use React slots

Table of contents need Core Idea Two ways to impl...

Introduction and use of js observer mode

Table of contents I. Definition 2. Usage scenario...

Summary of MySQL password modification methods

Methods for changing passwords before MySQL 5.7: ...

Detailed explanation of JavaScript program loop structure

Table of contents Select Structure Loop Structure...

How to block IP and IP range in Nginx

Written in front Nginx is not just a reverse prox...

Understanding and application of JavaScript ES6 destructuring operator

Table of contents Preface The role of deconstruct...

Implementation of dynamic rem for mobile layout

Dynamic rem 1. First, let’s introduce the current...

Summary of ten Linux command aliases that can improve efficiency

Preface Engineers working in the Linux environmen...

Solve the problem of Syn Flooding in MySQL database

Syn attack is the most common and most easily exp...