Default Webserver Nginx Ubuntu 18.04

Default Webserver Nginx Ubuntu 18.04

What is Nginx?

Nginx is an open source web server that is used to host websites or act as a reverse proxy for other web applications. Originally developed in Russia, Nginx is now widely used for its low resource usage and superior performance. It can easily handle thousands of requests at once and can serve static content quickly.

Nginx was specifically designed for modern, high-traffic websites and can handle more concurrent requests than Apache. Unlike Apache, Nginx is built from the ground up with performance in mind. It is highly efficient, secure, and reliable and can be used to host both static and dynamic websites.

Why Use Nginx?

There are numerous reasons why one might want to use Nginx. The primary reasons are its superior performance and scalability. Nginx is more efficient than Apache at serving static content, which is especially helpful for large websites. It can also handle a greater number of concurrent requests without suffering from performance issues, making it more reliable in high-traffic scenarios. Additionally, Nginx is considered to be more secure than Apache, which is especially important for hosting sensitive data.

Nginx also offers a number of features that are tailored for modern web applications. It can be used to easily set up URL redirects, load balance requests across multiple servers, and even cache static content. These features make it an ideal web server for hosting high-traffic or dynamic websites.

Installing Nginx on Ubuntu 18.04

Installing Nginx on Ubuntu 18.04 is a straightforward process. The first step is to update your package index. Open a terminal window and run the following command:

sudo apt-get update

Next, install Nginx using the following command:

sudo apt-get install nginx

Nginx will now be installed on your server. You should be able to access it by visiting the IP address of your server in a web browser. You should see the default Nginx page, which looks like this:

If you need to make any changes to the Nginx configuration, you can do so by editing the /etc/nginx/nginx.conf file. Once you make changes to this file, you can reload Nginx using the following command:

sudo nginx -s reload

Managing Nginx on Ubuntu 18.04

Once you have installed Nginx, you can manage it using the systemctl command. You can use this command to start, stop, and restart Nginx:

sudo systemctl start nginx (To start Nginx)

sudo systemctl stop nginx (To stop Nginx)

sudo systemctl restart nginx (To restart Nginx)

Setting up a Basic Firewall

By default, Nginx will be accessible on port 80 and 443. It is important to secure your server by setting up a basic firewall. You can do this by installing and configuring the ufw package. First, install ufwe:

sudo apt-get install ufw

Next, enable the firewall and allow the SSH, HTTP, and HTTPS ports:

sudo ufw enable (To enable the firewall)

sudo ufw allow ssh (To allow SSH connections)

sudo ufw allow http (To allow HTTP connections)

sudo ufw allow https (To allow HTTPS connections)

You can now verify the status of the firewall with the following command:

sudo ufw status

Configuring Nginx on Ubuntu 18.04

Now that Nginx has been installed and secured, you can start to configure it. The default configuration is located in the /etc/nginx/nginx.conf file. You can edit this file to customize the server's settings. Additionally, Nginx has several other configuration files located in the sites-available directory. These files will contain different settings for virtual hosts.

To set up a virtual host, first create a new config file in the sites-available directory with a name of your choice. For example, You can then add the following directives to this file:

server {
listen 80;
root /var/www/;

This configuration will tell Nginx to serve the content that is located in the /var/www/ directory when someone visits in a web browser. After adding the configuration, you can enable the virtual host by creating a symbolic link from the file to the sites-enabled directory.

Once you have enabled the virtual host, you can test the configuration with the nginx -t command. This will check the syntax of the configuration files and report any errors. Once you have confirmed that the configuration is correct, you can restart Nginx with the service nginx restart command.


In this guide, we have shown how to install and configure Nginx on an Ubuntu 18.04 server. We have also demonstrated how to set up a basic firewall and create a virtual host. With just a few simple steps, you can have a secure and high-performance web server to host your website.


Q. Is Nginx better than Apache?

A. Yes, Nginx is generally considered to be better than Apache in terms of performance and scalability. It is also considered to be more secure.

Q. How do I configure Nginx?

A. You can configure Nginx by editing the /etc/nginx/nginx.conf file. You can also create additional configuration files in the sites-available directory.

Q. How can I check the syntax of my Nginx configuration?

A. You can check the syntax of your Nginx configuration with the nginx -t command.

Thank you for reading this article. If you found it helpful, please consider reading our other articles.

Leave a Reply

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