Install the NGINX Web Server NGINX is a very powerful, bendy, and lightweight internet server that can effortlessly be established at the Linux platform. If your Linux distribution of choice is Ubuntu, that technique is even less difficult. Here we’ll stroll you thru the system of putting in the solid version of NGINX (1.14.Zero) at the modern day LTS (Long Term Support) release of Ubuntu Server (18.04).
Install the NGINX Web Server Why Install NGINX?
You might be asking your self, “Why installation NGINX while Apache has been the default internet server for years?” The answer is a chunk more complicated than you may assume. To simplify that solution, don’t forget Apache is an internet server that does an fantastic job of dealing with a huge quantity of requests in keeping with 2nd. However, Apache performance does start to warfare while requests growth. This way, when Apache server visits spike, web page load times can suffer.
On the other hand, NGINX is optimised to offer consistent and predictable overall performance. So even if web page visits spike, NGINX gained’t falter. On the flip facet, Apache is also some distance greater flexible than NGINX. With a incredible deal of modules and assist for different services and servers, Apache can (in the interim) do greater than NGINX. So if performance is what you’re searching out NGINX is your server. If flexibility is on top of your listing, Apache should be taken into consideration first.
Stopping and Disabling Apache
The first issue to be accomplished is stopping and disabling Apache. If Apache is going for walks at the server, NGINX can’t be installed. Apache can continue to be set up the equal server as NGINX, however unless Apache is stopped, NGINX will refuse to install. To find out if Apache is running, difficulty the command:
sudo systemctl fame apache2
If Apache is indexed as jogging, you need to forestall and disable it, so NGINX can be hooked up. To stop the Apache internet server, issue the command:
sudo systemctl forestall apache2
Disable the Apache server (so it doesn’t restart within the occasion of a server reboot) with the command:
sudo systemctl disable apache2
Installing NGINX
With Apache looked after, the set up of NGINX may be accomplished with a single command:
sudo apt-get set up nginx
Once hooked up, start and allow NGINX with the following instructions:
sudo systemctl begin nginx
sudo systemctl permit nginx
The NGINX web server is now set up and going for walks.
Install the NGINX Web Server Viewing the NGINX Welcome Page
Now that NGINX is established, you may point your web browser to the IP cope with of the website hosting server to look the NGINX Welcome Page. If you’re no longer certain of your server’s IP address, issue the command:
ip a
The output of the above command will show your server deal with.
Chances are, you’ll run into a hassle when looking to view the default NGINX index.Html web page. The problem is that, if Apache turned into hooked up first, NGINX will serve up the Apache index.Html page by way of default. In order to look the NGINX Welcome Page (index.Nginx-debian.Html), the Apache Welcome Page ought to be renamed. Back at the terminal window, trouble the command:
sudo mv /var/www/html/index.Html /var/www/html/index.Html.Old
Go returned to your net browser and reload that web page. The Apache Welcome Page need to now be replaced by means of the NGINX Welcome Page.
Install the NGINX Web Server HOW TO CONFIGURE A WEB SITE
With NGINX established and strolling, it is now time to setup your first internet page. How NGINX sites are configured is executed very much like Apache. Let’s stroll thru the basics of setting up a barebones website online. The first thing you want to recognize are the vital directories that residence the files utilized in growing a site. These directories are:
- /var/www/html — this is the NGINX file root, wherein all your website directories and pages could be housed.
- /and so on/nginx/websites-available — that is the directory that houses all the configuration documents for each of your web sites.
- /etc/nginx/web sites-enabled — that is the directory that instructs NGINX which websites are really enabled for the server.
The difference between websites-available and websites-enabled is twofold:
- web sites-to be had are real files for every website online you have created for the server.
- Websites-enabled are hyperlinks to the documents in sites-to be had. Unless there is a hyperlink in websites-enabled, NGINX will now not be privy to a website in websites-available.
HOW TO CONFIGURE A WEB SITE
Out of the container, there could be a single record in /and so forth/nginx/web sites-to be had. That report is default. What we’re going to do is create a new (bare minimum) web site. The first component that ought to be achieved is to create a directory (inside the NGINX file root) to residence our internet site. We’ll call that web page take a look at. From the terminal window, problem the command:
sudo mkdir /var/www/html/test
Create an index.html file with the command:
sudo nano /var/www/html/test/index.html
Inside that document, add the following:
<H1>HELLO LIFEWIRE!</H2>
Save and close the file with the command Ctrl-x. Give the directory the necessary permissions with the commands:
sudo chown www-data:www-data -R /var/www/html/test
sudo chmod -R 755 /var/www/html/test
Now create a configuration file for our new site in /etc/nginx/sites-available with the command:
HOW TO CONFIGURE A WEB SITE
Inside that file, add the following content:
server {
listen 80;
listen [::]:80;
root /var/www/html/test;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
Save and close that file.
Test the NGINX configuration with the command:
sudo nginx -t
The test will display as a success. In order to ensure NGINX can show the newly crafted test website, restart the net server with the command:
sudo systemctl restart nginx
You can now point your browser to http://SERVER_IP/test (Where SERVER_IP is the IP address of your server) to look the newly created index.Html record displayed.