Setting up Nginx

Nginx is a popular high-performance webserver. Many users prefer it over apache for its quick page render time and low memory utilization, making it a perfect fit for both small and large VPSes. Nginx is compatible with HTML, PHP, and many other media.

 

Step 1 - Installing nginx

apt-get is a program that manages all of Debian’s repositories for you. Its primary function is to install and uninstall packages from your system.

To install nginx, start an SSH session on your VPS and run the command shown here:

 

$ sudo apt-get update && sudo apt-get install nginx -y



Step 2 - Change working directory

By default, nginx will serve content located in /usr/share/nginx/www. To make updating the site easier, we will configure nginx to serve content from a system-wide location. To do this, we run:

 

$ sudo nano /etc/nginx/sites-enabled/default

 

Look for this line:

 

root /usr/share/nginx/www;

 

and change it to the path shown here:

 

root /var/www/public_html;

 

Press control+x , y, and then enter. Now, we will make the new working directory and then copy the contents of the old working directory into our new working directory:

 

$ sudo mkdir -p /var/www/public_html

$ sudo cp /usr/share/nginx/www/* /var/www/public_html/

 

We need to make sure that nginx can read and write to the working directory.

$ sudo chown -R www-data:www-data /var/www

 

Finally, we restart nginx.

 

$ sudo service nginx restart

 

Step 3 - Verify nginx is running

Navigate to your VPS in a web browser, and if you see “Welcome to nginx!”, nginx is working correctly! Now you can modify your website by changing the files in the web root we’ve set.

Was this answer helpful?

 Print this Article

Also Read

How to install Let's Encrypt free SSL plugin on cPanel server?

Let's Encrypt plugin allows automated SSL certificate for those account which do not have valid...

How do I reset my cPanel password?

You are able to easily reset your cPanel password via our billing and support control panel.Below...

Edit Windows `hosts` File to Preview Content

Need to preview your site on a new server before DNS propagates? Here is the best method...

How do I create an addon domain in cPanel?

Once logged into your cPanel account, addon domains are located under the "Domains" section....

Protecting SSH with Fail2Ban

If a server is exposed to the Internet, attackers will scan that server for as many...

Powered by WHMCompleteSolution