Table of Contents
Nginx is becoming a highly popular option for users looking for a powerful resource-friendly web server or a reverse proxy to their existing Apache server configuration.
In this article, we’ll show you how to install Nginx in your Ubuntu 16 Cloud VPS Hosting account and set it up as a reverse proxy for Apache.
Apache is Already Installed
You may have noticed when first setting up your account that Apache is already installed and working as your active web server. (You can verify this by visiting your primary domain and seeing the Ubuntu server default page.)
This means you’ll likely find most success using Nginx as a reverse proxy, which we will show you how to do in this article.
Install Nginx
The first step in this process is to install Nginx. Make sure you are logged into your VPS with the sudo user you created. You will just need to run this command and respond “Yes” to any installation prompts that may pop up:
Once the installation is complete, we will begin configuring Apache and Nginx.
Configure Apache
We will first need to change the default ports for accessing Apache. By changing the default port for Apache, we will be making sure that Nginx has the first opportunity to serve any static resources needed.
You can use the nano text editor to edit the ports file:
Update the “Listen” line, changing the port number from 80 to 8000:
We will also need to edit the configuration file for virtual hosts:
Changing the port again:
Make sure to restart the Apache service:
Those are the essential configurations for Apache. There are more advanced configurations you can apply, but these port changes cover the basics.
Configure Nginx
Now we will need to configure Nginx to serve as our reverse proxy.
Make sure that Nginx services are enabled:
Restart Nginx to make sure any changes are applied:
Now we will add some proxy parameters to the necessary configuration file:
Add the extra parameters to the bottom of the proxy_params
file (Bear in mind, the +
signs are added to demonstrate the additional lines and should not be included in your file. For a plain text version of the file you can copy and paste, click here.):
As we did above for Apache, we will next be editing the virtual hosts configuration file, this time for Nginx:
Make sure that the document root is the same for Nginx, and make sure to include our proxy parameters file. An easy way to make this change would be copy your existing configuration file first:
Now you have an untouched version of the file your distribution came with; this way you can safely delete the contents of the original and paste in these lines:
Make sure to “reload” Nginx in order to apply these new settings.
How to Test Your Configuration
You’ll notice that if you reload your page in a browser, you will not see any immediate change. So how do we know if our changes took effect?
There are many different ways to do this, but one easy way is to run this command from your local computer in a new terminal window, of course making sure to substitute “https://example.com” for the primary domain of your site:
The output of this command will return information about your server. If you see “Server: nginx/1.10.3 (Ubuntu)” then you completed this tutorial correctly and you now have Nginx configured as a reverse proxy for Apache.
Learn more from our Cloud Server Hosting Product Guide.
With our Cloud Server Hosting, you can deploy a lightning-fast, reliable cloud platform with built-in redundancy – ensuring the availability of your environment!