Server-tutorials.net
  • Home
  • CentOS
    • All
    • Game Hosting
    • Hosting Control Panel
    How to Install Laravel on CentOS 8 Linux Server

    How to Install Laravel on CentOS 8 Linux Server

    How to Host a Minecraft Server on a CentOS 8 Server

    How to Host a Minecraft Server on a CentOS 8 Server

    How to Install and Configure an Email Server on CentOS 8 (dovecot,postfix,mariadb,roundcube)

    How to Install and Configure an Email Server on CentOS 8 (dovecot,postfix,mariadb,roundcube)

    How To Set Up a Firewall Using FirewallD on CentOS 7

    How To Set Up a Firewall Using FirewallD on CentOS 7

    How to Install VestaCP on CentOS 7: A Comprehensive Guide

    How to Install VestaCP on CentOS 7: A Comprehensive Guide

    engineer holding laptop

    How to Install cPanel on CentOS 8: A Comprehensive Guide

    close up photo of ethernet cables on network switch

    Setup a Firewall Using FirewallD on CentOS 7

    security logo

    Installing and Configuring a Firewall on CentOS 8 Server

    Step-by-Step Guide how to Install Elgg on Debian 12

    Setp-by-Setp Guide how to Install Elgg on CentOS 7

    Step-by-Step Guide: How to Install Elasticsearch 8 on Debian 11

    Installing Elasticsearch on CentOS 7

    Custom installation VestaCP on Debian/Ubuntu (Nginx,Apache2)

    How to install VestaCP on CentOS

    Trending Tags

    • centos
  • Debian
    • All
    • Game Hosting
    • Hosting Control Panel
    How to Install and Configure an Email Server on Debian 11 (Postfix, Dovecot, and Roundcube)

    How to Install and Configure an Email Server on Debian 11 (Postfix, Dovecot, and Roundcube)

    How to Install LEMP Stack on Debian 11 Server

    How to Install LEMP Stack on Debian 11 Server

    How to Identify and Remediate Security Breaches or Malware on Your Debian 12 Server

    How to Identify and Remediate Security Breaches or Malware on Your Debian 12 Server

    Upgrading ISPConfig from Debian 11 to Debian 12

    Upgrading ISPConfig from Debian 11 to Debian 12

    How to Downgrade PHP Version on Debian 11: A Step-by-Step Guide

    How to Downgrade PHP Version on Debian 11: A Step-by-Step Guide

    How to Host an OpenRA Game Server on Debian 12

    How to Host an OpenRA Game Server on Debian 12

    How to Install WireGuard VPN on Debian 12: A Step-by-Step Guide

    How to Install WireGuard VPN on Debian 12: A Step-by-Step Guide

    black headphones on black laptop computer

    How to Host a Counter-Strike: Global Offensive Game Server on Debian 12

    close up photo of ethernet cables on network switch

    How to Create a User for ProFTPD Server on Debian 12

    close up photo of mining rig

    Debian 12 (Bookworm) Setup with Apache, BIND, Dovecot, PureFTPD, and ISPConfig 3.2

    wooden robot

    How to Host a Minecraft Server on Debian 12: A Step-by-Step Guide

    modern computer placed near server racks

    Installing and Configuring a Firewall on Debian 12 Server

    black server racks

    A Comprehensive Guide to Backing Up a Debian 12 Server

    data codes through eyeglasses

    How to Install OpenVPN on Debian 12 Server: A Step-by-Step Guide

    close up photo of plugged cables

    Setting Up a Secure FTP Server on Debian 12

    Installing PostgreSQL 15 on Debian 11 Step-by-Step Tutorial

    Installing PostgreSQL 15 on Debian 11 Step-by-Step Tutorial

    Installing Tomcat 10 on Debian 11: Step-by-Step Guide

    Installing Tomcat 10 on Debian 11: Step-by-Step Guide

    Step-by-Step Guide how to Install Elgg on Debian 12

    Step-by-Step Guide how to Install Elgg on Debian 12

    Step-by-Step Guide: How to Install Elasticsearch 8 on Debian 11

    Step-by-Step Guide: How to Install Elasticsearch 8 on Debian 11

    Installing Laravel on Ubuntu 22.04 / Ubuntu 20.04: A Step-by-Step Guide

    Installing Laravel on Ubuntu 22.04 / Ubuntu 20.04: A Step-by-Step Guide

    Trending Tags

    • debian
    • debian 10
  • Ubuntu
    • All
    • Game Hosting
    • Hosting Control Panel
    • Network Monitoring
    How to Upgrade PHP from 7.2 to 7.4 and 8.0 on VestaCP Ubuntu 18.04

    How to Upgrade PHP from 7.2 to 7.4 and 8.0 on VestaCP Ubuntu 18.04

    Securing Nginx with Let’s Encrypt on Ubuntu 22.04: A Step-by-Step Guide

    Securing Nginx with Let’s Encrypt on Ubuntu 22.04: A Step-by-Step Guide

    How to install Counter-Strike: Global Offensive CSGO on Ubuntu 22.04 Server

    How to install Counter-Strike: Global Offensive CSGO on Ubuntu 22.04 Server

    Step-by-Step Guide: Installing Terraform on Ubuntu Server 22.04

    Step-by-Step Guide: Installing Terraform on Ubuntu Server 22.04

    How to Deploy a Secure CockroachDB Cluster on Ubuntu 22.04

    How to Deploy a Secure CockroachDB Cluster on Ubuntu 22.04

    How to Downgrade PHP Version on Ubuntu 22.04: A Step-by-Step Guide

    How to Downgrade PHP Version on Ubuntu 22.04: A Step-by-Step Guide

    How to Install and Configure an Email Server on Ubuntu 22.04 (Postfix, Dovecot, and Roundcube)

    How to Install and Configure an Email Server on Ubuntu 22.04 (Postfix, Dovecot, and Roundcube)

    How to Install Zabbix Monitoring Tool on Ubuntu 22.04

    How to Install Zabbix Monitoring Tool on Ubuntu 22.04

    How to Install Apache Guacamole via Docker on Ubuntu 22.04

    How to Install Apache Guacamole via Docker on Ubuntu 22.04

    How to Install and Configure a Proxy Server on Ubuntu 22.04 Server

    How to Install and Configure a Proxy Server on Ubuntu 22.04 Server

    close up photo of programming of codes

    How to Setup Zabbix Monitoring Tool on Ubuntu 22.04

    modern computer placed near server racks

    How to Install Plesk on Ubuntu 22.04 Server: A Comprehensive Guide

    Free server network image

    How to Install ClickHouse on Ubuntu 22.04: A Step-by-Step Guide

    man people night dark

    Installing and Configuring a Firewall on Ubuntu 22.04 Server

    ethernet cables plugged in network switch

    Securing Nginx on Ubuntu 22.04: Best Practices and Step-by-Step Guide

    close up photo of ethernet cables on network switch

    Installing FileRun on Ubuntu 22.04

    cables connected to ethernet ports

    How to Install ClickHouse on Ubuntu 22.04

    engineer holding laptop

    Install OpenNMS Network Monitoring System on Ubuntu 22.04

    Step by Step Guide how to install CakePHP on Ubuntu 22.04

    Step by Step Guide how to install CakePHP on Ubuntu 22.04

    Installing MySQL on Ubuntu 22.04: A Step-by-Step Guide

    Installing MySQL on Ubuntu 22.04: A Step-by-Step Guide

    Trending Tags

    • Ubuntu 20.04 LTS
    • Ubuntu 20.04
  • Others
    • All
    • Beginners
    industry internet connection technology

    Understanding the Differences Between Nginx and Apache

    Free server network image

    How to Install ClickHouse on Ubuntu 22.04: A Step-by-Step Guide

    crop hacker typing on laptop with data on screen

    Choosing Between VPS and Dedicated Server: A Comprehensive Comparison

    unrecognizable hacker with smartphone typing on laptop at desk

    Choosing the Best Control Panel for Server Management: A Comprehensive Guide

    close up photo of ethernet cables on network switch

    Installing FileRun on Ubuntu 22.04

    cables connected to ethernet ports

    How to Install ClickHouse on Ubuntu 22.04

    Installing Tomcat 10 on Debian 11: Step-by-Step Guide

    Installing Tomcat 10 on Debian 11: Step-by-Step Guide

    Step-by-Step Guide how to Install Elgg on Debian 12

    Step-by-Step Guide how to Install Elgg on Debian 12

    Step-by-Step Guide: How to Install Elasticsearch 8 on Debian 11

    Step-by-Step Guide: How to Install Elasticsearch 8 on Debian 11

    Trending Tags

    • php
No Result
View All Result
Server-tutorials.net
Home Nginx

How to use nginx as reverse proxy on ubuntu 20.04

Chris Thompson by Chris Thompson
September 26, 2023
in Nginx, Ubuntu
0

Introduction

Nginx is open-source software that is popular worldwide for its web-serving features. Initially, it was designed as the fastest and most stable webserver. Later on, its features included caching, reverse proxy, load balancing, media streaming, and much more. What makes Nginx popular among the top web servers? Its high performance and quick stable loading make it a heart favorite of proxy users.

This blog will educate you about the exclusive features of Nginx. Further, how to use Nginx reverse proxy for two different apps using two subdomains. We will also discuss the procedure to set up the Nginx reverse proxy via local resolution. It will help you to create a mirror setup instantly. For better and quick understanding, we will use the HTTP tutorial. But the users can also use the same configuration setup for HTTPS.

For developing a static web server, SimpleHTTPServer- a product of Pathon will be used. Similarly, we will use Python to develop dynamic new apps.

Nginx –the fastest web-server

Before moving to the main topic, it is necessary to have a look at the Nginx features as a web server.

Nginx is the open-source web server that is popular and widely used among high-traffic sites. The most intensive websites like NASA, WordPress.com, and Netflix are also the users of Nginx.

Nginx uses an asynchronous mechanism that makes it more favorable. This mechanism uses a single thread to handle the requests. Thus, it utilizes low memory and is highly concurrent. As Nginx is asynchronous, it smoothly handles abundant requests without blocking or slowing down the sites.

Nginx has wider applications in the web serving world like:

  • IPv6
  • Load balancing
  • Media Streaming
  • Fast CGI support with caching
  • Reverse proxy with caching
  • Handles static files, index files, and creation of the auto-index

Nginx is a diverse web server that serves the IT world surprisingly. If you have not used it yet, try some of its features.

System requirements

For the users’ understanding, we have been using BitLaunch Ubuntu 20.04 LTS VPS for Nginx reverse proxy lessons. You can get connected to your VPS via Putty or any other SSH client servers. However, any new Unbuntu server can also be used using the given commands in the tutorial.

How to Prepare the servers?

Before the installation of Nginx, it is necessary to prepare the server for changes in the setup.  Firstly, we need to update the local package index. If any outdated package exits, there is a need to upgrade it to move further.

Otherwise, Nginx reverse proxy may not get installed or work properly.

$ apt-get update

Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease

Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease

Hit:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease

Hit:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease

Reading package lists... Done
$ apt-get -y upgrade

Reading package lists... Done

Building dependency tree      

Reading state information... Done

Calculating upgrade... Done

The following packages were automatically installed and are no longer required:

....

....

 

Install Nginx Server

Nginx is among the default repositories of Unbuntu. So, the users need not add external repositories. All these repositories follow the mirror of the official versions. For the latest and true repository, it is better to fulfill the requirements of Nginx Installation and documents.

When the server is prepared, it is time to install the Nginx package via the apt package manager. For the Nginx installation, you can watch a detailed method on the Nginx installation tutorial.

$ apt install -y Nginx

Reading package lists... Done

Building dependency tree      

Reading state information... Done

....

....

Verify & configure Nginx Version

As the installation gets completed, the user needs to verify the Nginx version. Further, it also demands configuration with the -V flag.

$ nginx -V
nginx version: nginx/1.17.10 (Ubuntu)

built with OpenSSL 1.1.1f  31 Mar 2020

TLS SNI support enabled

configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-Pmk9_C/nginx-1.17.10=. -fstack-protector-strong -

....

....

Access the external server by configuring a Firewall

At this point, if you want to allow external access to your server, allow port 80. If you are not interested, skip this process.

$ sudo ufw allow 80

Install Python and HTTPie

Finally, at this step, we are ready to create two apps. To develop the apps, we will use the Python platform. as described earlier, Python is the default repository. So, the process will continue smoothly.

We will use Python to create our two apps, so let’s install the required packages. Python is included in the default package repositories.

$ apt install -y python

Here, the system will ask for verification and testing. You can use HTTPie or Curl.

$ apt install -y httpie

Make Sure NGINX Starts After Boot

You need to enable Nginx to start after boot. Give a command to the system that after booting you need Nginx start.

$ sudo systemctl enable nginx

Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install enable nginx

Start NGINX Server

Here the system is ready to start the Nginx server.

$ systemctl start nginx

How to create two Apps using two domains?

Now, we are going to develop two apps using two domains. In this way, you can test your setup as well. For this purpose, we will use the Python platform and its module SimpleHTTPServer. Python’s SimpleHTTPServer is a static web server that cannot be used for development purposes. However, it is an excellent tool for testing the services.

Service A

Create the Content for App A

Follow the given commands to achieve the goal.

$ mkdir appA
$ cd appA
$ cat <<EOF >index.html

this is app A !

EOF

Start the Web Server for App A

In the command window, “&” is mentioned. It allows the whole process to run in the background and you can use the shell for other purposes. For instance, a shell can have prints of STDOUT logs.

For Python 2

$ python -m SimpleHTTPServer 3000 &
$ Serving HTTP on 0.0.0.0 port 3000 ...

For Python 3

$ python3 -m http.server 3000 &

Serving HTTP on 0.0.0.0 port 3000 (http://0.0.0.0:3000/) …

Test App A

The app content is ready to tets via HTTPie-http client.

$ http http://localhost:3000
127.0.0.1 - - [24/May/2020 13:30:59] "GET / HTTP/1.1" 200 -

HTTP/1.0 200 OK

Content-Length: 16

Content-type: text/html

Date: Sun, 24 May 2020 13:30:59 GMT

Last-Modified: Sun, 24 May 2020 13:28:42 GMT

Server: SimpleHTTP/0.6 Python/2.7.18rc1

this is app A !

It works amazingly. You can observe all content of App A on port 3000.

Service B

Create the Content for App B

$ mkdir appB
$ cd appB
$ cat <<EOF >index.html

this is app B !

EOF

Start the Web Server for App B

Again, in the command window, “&” is mentioned. It allows the whole process to run in the background and you can use the shell for other purposes. For instance, the shell can have prints of STDOUT logs.

For Python 2

$ python -m SimpleHTTPServer 4000 &
$ Serving HTTP on 0.0.0.0 port 4000 ...

For Python 3

$ python3 -m http.server 4000 &

Serving HTTP on 0.0.0.0 port 4000 (http://0.0.0.0:4000/) …

Test App B

Now, you can test your app B via HTTPie http client.

$ http http://localhost:4000

127.0.0.1 – – [24/May/2020 13:39:18] “GET / HTTP/1.1” 200 –

HTTP/1.0 200 OK

Content-Length: 16

Content-type: text/html

Date: Sun, 24 May 2020 13:39:18 GMT

Last-Modified: Sun, 24 May 2020 13:38:23 GMT

Server: SimpleHTTP/0.6 Python/2.7.18rc1

this is app B !

Superb! You can observe all content of App B on port 4000.

How to setup Nginx Reverse Proxy using Local resolution

To differentiate two apps, it is necessary to use two different domains. You can use any fake or supposed domain like domain.com. It can be like the given below:

  • For App A:domain.com
  • For App B:domain.com

The system will ask for the two entries before the DNS resolution. Here, you need to develop in the /etc/hosts file.

$ sudo cat <<EOF >> /etc/hosts

127.0.0.1 appa.domain.com

127.0.0.1 appb.domain.com

EOF

How to configure NGINX as a Reverse Proxy Server

When you have customized the setup and install python and HTTPie, the system is ready to configure Nginx as a Reverse Proxy. The Host header regulates the type of request as per the webserver. In simpler words, the Nginx configuration determines that a certain type of request needs to pass to a certain web server. Thus, users can smoothly use the Nginx reverse proxies.

Here is the need to delete the default configuration symlink at the enables-sites.

$ rm /etc/nginx/sites-enabled/default

Then create the configuration file on the available under-sites:

$ touch /etc/nginx/sites-available/reverse-proxy

Create the new symlink on the enables-under sites:

$ ln -s /etc/nginx/sites-available/reverse-proxy /etc/nginx/sites-enabled/reverse-proxy

Choose the desired editor (nano or any other editor) and edit the configuration file:

$ nano /etc/nginx/sites-available/reverse-proxy

Here we have fulfilled all requirements to configure the reverse proxy. Nginx server uses and prefers the upstream module. The upstream modules are used for load balancing. But there are other methods also.

Finally, command the given statements into nano or the desired editor and exit using Ctrl-X.

upstream appA {

        server 127.0.0.1:3000;

}


upstream appB {

        server 127.0.0.1:4000;

}


server {

  listen 80;

  server_name appa.domain.com;


  location / {

        proxy_pass http://appA;

    }

}


server {

  listen 80;

  server_name appb.domain.com;




  location / {

        proxy_pass http://appB;

    }

}

To sum up the procedure, both upstream features define app A and app B. One is shown on port 3000 and the other one in port 4000. Server directive and domain name are the main configuration titles. The Host header is used to determine the subdomains and upstream mapping.

Test the Nginx Reverse proxy Configuration

To complete the procedure flawlessly, it is better to assess the Nginx Reverse proxy configuration.

In case you do not test the configuration, it may cause issues in load balancing and other functioning of the server. In simpler words, if you have a non-valid configuration, the server may have more downtime after a restart. IT experts advise the Nginx users to tets the reverse proxy configuration to avoid delay time.

$ sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload NGINX Server

First, reload the nginx web server. It will help to show all new configurations.

$ sudo systemctl reload nginx

Check the status of the NGINX Server

You can check the status of the Nginx server using the given commands.

$ sudo 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: enabled)

     Active: active (running) since Sun 2020-05-24 13:16:41 UTC; 3min 16s ago

       Docs: man:nginx(8)

    Process: 3525 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)

   Main PID: 3331 (nginx)

      Tasks: 2 (limit: 614)

     Memory: 4.2M

     CGroup: /system.slice/nginx.service

             ├─3331 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

             └─3526 nginx: worker process




May 24 13:16:41 5eca7132aa8cc30001a9eb8b systemd[1]: Starting A high performance web server and a reverse proxy server...

May 24 13:16:41 5eca7132aa8cc30001a9eb8b systemd[1]: Started A high performance web server and a reverse proxy server.

May 24 13:19:38 5eca7132aa8cc30001a9eb8b systemd[1]: Reloading A high performance web server and a reverse proxy server.

May 24 13:19:38 5eca7132aa8cc30001a9eb8b systemd[1]: Reloaded A high performance web server and a reverse proxy server.

Verify the setup

It is time to see the results of your struggle. Test the two apps and the validity of the Nginx configuration. For this purpose, the requests will proceed from HTTP client-HTTPie. HTTPie will forward a request to appa.domain.com and appb.domain.com. If the correct web server shows the desired app content, it reveals your success.

App A

Send an HTTP request to host appa.domain.com

You can see the app A content via appa.domain.com.

App B

Send an HTTP request to host appb.domain.com

You can view the app B content via appb.domain.com.

Conclusion

The article has described the Nginx configuration simply. Further, set up of two different apps using two domains as well as how to reload the Nginx proxy server. While describing the promised procedures, we have skipped the performance features and several other settings. You can toggle them to settle well.

Tags: howtonginxreverse proxytutorialUbuntu 20.04
Previous Post

How to host a Tor .onion site on a Debian Server (nginx + tor)

Next Post

How to install and Set up osTicket with Nginx on Debian 11

Chris Thompson

Chris Thompson

Next Post
How to install and Set up osTicket with Nginx on Debian 11

How to install and Set up osTicket with Nginx on Debian 11

How to Install and Set up Wireguard VPN on Debian 11

How to Install and Set up Wireguard VPN on Debian 11

How to Install a Teleport Cluster on Debian 11 server

How to Install a Teleport Cluster on Debian 11 server

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categorys

  • AI Server Technology
  • Apache
  • Backup
  • CentOS
    • Game Hosting
    • Hosting Control Panel
  • Crypto
  • Debian
    • Game Hosting
    • Hosting Control Panel
  • Email
  • FTP
  • Laravel
  • MySQL
  • Nginx
  • Others
    • Beginners
  • PHP
  • Security
    • Firewall
  • Tor Hosting
  • Ubuntu
    • Game Hosting
    • Hosting Control Panel
      • Plesk
      • VestaCP
    • Network Monitoring
  • VNC
  • VPN
  • Webhosting

Popular Posts

  • How to install WHM & CPanel on Ubuntu 20.04 LTS Linux

    How to install WHM & CPanel on Ubuntu 20.04 LTS Linux

    664 shares
    Share 266 Tweet 166
  • Ubuntu 20.04 LTS Nginx Performance Optimization

    606 shares
    Share 242 Tweet 152
  • How to host a Tor .onion site on a Debian Server (nginx + tor)

    602 shares
    Share 241 Tweet 151
  • How to upgrade php7.2 to php7.4 in VestaCP on Ubuntu ?

    601 shares
    Share 240 Tweet 150
  • How to use nginx as reverse proxy on ubuntu 20.04

    600 shares
    Share 240 Tweet 150

Recent Posts

How to Upgrade PHP from 7.2 to 7.4 and 8.0 on VestaCP Ubuntu 18.04

How to Upgrade PHP from 7.2 to 7.4 and 8.0 on VestaCP Ubuntu 18.04

September 26, 2023
How to Install Laravel on CentOS 8 Linux Server

How to Install Laravel on CentOS 8 Linux Server

September 26, 2023
Securing Nginx with Let’s Encrypt on Ubuntu 22.04: A Step-by-Step Guide

Securing Nginx with Let’s Encrypt on Ubuntu 22.04: A Step-by-Step Guide

September 14, 2023

About Us

Server-tutorials.net - Linux Debian, Ubuntu, CentOS Server Tutorials.

Popular Tag

7.2 7.4 18.04 22.04 Apache apache2 backup server centos CentOS 7 centos 8 cpanel debian debian 11 Dovecot Elasticsearch firewall centos 8 FTP Server how to howto How to Install ClickHouse on Ubuntu 22.04 install installation kvm lavarel lemp linux mariadb MySQL nginx node openvz php Postfix server setup tutorial ubuntu Ubuntu 20.04 Ubuntu 22.04 update vesta vestacp vnc vserver Wireguard

Recent News

How to Upgrade PHP from 7.2 to 7.4 and 8.0 on VestaCP Ubuntu 18.04

How to Upgrade PHP from 7.2 to 7.4 and 8.0 on VestaCP Ubuntu 18.04

September 26, 2023
How to Install Laravel on CentOS 8 Linux Server

How to Install Laravel on CentOS 8 Linux Server

September 26, 2023
  • Cookie Policy
  • Privacy & Policy
  • Change privacy settings
  • Privacy settings history
  • Revoke consents
  • Contact
  • Imprint

© 2022 Server-tutorials.net - Linux Server Tutorials

No Result
View All Result
  • Home
  • CentOS
    • Hosting Control Panel
  • Debian
    • Backup
    • FTP
    • Hosting Control Panel
    • Laravel
    • Laravel
    • Network Monitoring
    • Security
      • Firewall
    • Tor Hosting
    • VPN
    • Webhosting
  • Ubuntu
    • VestaCP
    • Nginx
  • Others
    • Beginners
  • Contact
  • Privacy Policy
  • Cookie Policy
  • Imprint

© 2022 Server-tutorials.net - Linux Server Tutorials