Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Set Up an Nginx Reverse Proxy
#1


How to Set Up an Nginx Reverse Proxy



Now, we will configure Nginx in front of an Apache web server. We chose the Apache server because it’s better at handling dynamic content.


So, all the static content will go to Nginx, while the dynamic content will go to Apache. This will improve performance by optimizing the delivery of content based on the handling criteria.


Next, we will define the IP address of the Nginx Proxy Server as 192.x.x.1 and the back-end Apache server as 192.x.x.2. After setting up Apache, we can move on to these steps:


1. Install Nginx


We’ll be using the apt command on Ubuntu 18.04:


sudo apt-get update
sudo apt-get install nginx

2. Disable the Default Virtual Host


Once you have installed Nginx, follow the below command to disable the virtual host:


sudo unlink /etc/nginx/sites-enabled/default

3. Create the Nginx Reverse Proxy


After disabling the virtual host, we need to create a file called reverse-proxy.conf within the etc/nginx/sites-available directory to keep reverse proxy information.


For this, we should first access the directory using the cd command:


cd etc/nginx/sites-available/

Then we can create the file using the vi editor:


vi reverse-proxy.conf

In the file, we need to paste in these strings:


server {
    listen 80;
    location / {
        proxy_pass http://192.x.x.2;
    }
}

In the above command, the considerable point is the proxy pass is allowing the requests coming through the Nginx reverse proxy to pass along to 192.x.x.2:80, which is Apache remote socket. Thus, both the web servers – Nginx and Apache, share the content.


Once completed, simply save the file and exit the vi editor. You can do this by keying in :wq.


To pass information to other servers, you can use the ngx_http_proxy_module in the terminal.


Now, activate the directives by linking to /sites-enabled/ using the following command:


sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf

4. Test Nginx and the Nginx Reverse Proxy


Lastly, we need to run an Nginx configuration test and restart Nginx to check its performance. Type the below command to verify the Nginx functioning on the Linux terminal:


service nginx configtest
service nginx restart

Remember, if you receive a failed test, that most likely indicates that Apache was not properly set up.




Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)