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

Simple writing of MYSQL stored procedures and functions

What is a stored procedure Simply put, it is a se...

mysql5.7.17.msi installation graphic tutorial

mysql-5.7.17.msi installation, follow the screens...

Detailed explanation of the flexible use of CSS grid system in projects

Preface CSS grids are usually bundled in various ...

Use of Linux relative and absolute paths

01. Overview Absolute paths and relative paths ar...

More popular and creative dark background web design examples

Dark background style page design is very popular...

Detailed explanation of mysql integrity constraints example

This article describes the MySQL integrity constr...

Detailed installation steps for MySQL 8.0.11

This article shares the installation steps of MyS...

Regular expression usage in CSS selectors

Yes, CSS has regular expressions too (Amen) Two p...

How to use vue3+TypeScript+vue-router

Table of contents Easy to use Create a project vu...

Form submission page refresh does not jump

1. Design source code Copy code The code is as fol...

HTML tags explained

HTML tags explained 1. HTML tags Tag: !DOCTYPE De...

JS implements a detailed plan for the smooth version of the progress bar

The progress bar is not smooth I believe that mos...

Explanation of MySQL index types Normal, Unique and Full Text

MySQL's index types include normal index, uni...

Detailed explanation of CSS animation attribute keyframes

How long has it been since I updated my column? H...