Nginx is a powerful web server software that can be used on your server. It is also known for its high performance and low memory usage which will allow fewer resources to be used but getting the job done efficiently. A popular set up is to use it as a proxy for Apache, which can then serve application requests.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Nginx on a Ubuntu 18.04 (Bionic Beaver) server.
Install Nginx on Ubuntu 18.04 LTS Bionic Beaver
Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.
sudo apt-get update sudo apt-get upgrade
Step 2. Installing Nginx.
Installing nginx package on Ubuntu 18.04 Bionic Beaver) is as easy as running:
apt-get install nginx
After that, run the commands to enable Nginx to automatically startup when your server starts:
sudo systemctl stop nginx.service sudo systemctl start nginx.service sudo systemctl enable nginx.service
To test Nginx setup, open your browser and browse to the server hostname or IP address and you should see Nginx default test page as shown below:
Step 3. Configure Nginx.
Nginx site-specific configuration files are kept in /etc/nginx/conf.d/. Generally you will want a separate file in this directory for each domain or subdomain you will be hosting.
Copy the default configuration file. Replace wpcademy.com with your website’s domain name or your public IP address.
sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/https://wpcademy.com.conf
Open your site’s configuration file in a nano text editor. Replace example.com in the server_name directive with your site’s domain name or IP address. If you already have content ready to serve (such as a WordPress installation) replace the path in the root directive with the path to your site’s content:
server { listen 80; server_name wpcademy.com; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
Test your configuration for errors:
nginx -t
Step 4. Configure the Firewall for Nginx.
Firewall software needs to be adjusted to allow access to the service. Nginx registers itself as a service with ufw upon installation, making it straightforward to allow Nginx access:
sudo ufw allow 'Nginx HTTP'
Congratulations! You have successfully installed Nginx. Thanks for using this tutorial for installing Nginx web server in Ubuntu 18.04 LTS (Bionic Beaver) system. For additional help or useful information, we recommend you to check the official Nginx web site.