Install NGINX on Ubuntu 18.04
Updated by Linode Written by Linode

What is NGINX?
NGINX is an open source web server with powerful load balancing, reverse proxy, and caching features. It was initially designed to solve scaling and concurrency problems with existing web servers. Its event-based, asynchronous architecture has made it one of the most popular and best-performing web servers available.
Install NGINX
Currently, the best way to install NGINX on Ubuntu 18.04 is to use the version included in Ubuntu’s repositories:
sudo apt update
sudo apt install nginx
Configure NGINX
Add Basic Site
NGINX site-specific configuration files are kept in /etc/nginx/sites-available and symlinked into /etc/nginx/sites-enabled/. Generally you will want to create a separate original file in the sites-available directory for each domain or subdomain you will be hosting, and then set up a symlink in the sites-enabled directory.
Copy the default configuration file. Replace
example.comwith your website’s domain name or your Linode’s public IP address.sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.comDisable the default configuration file by removing the symlink in
/etc/nginx/sites-enabled/:unlink /etc/nginx/sites-enabled/defaultOpen your site’s configuration file in a text editor. Replace
example.comin theserver_namedirective with your site’s domain name or IP address. If you already have content ready to serve (such as a WordPress installation or static files) replace the path in therootdirective with the path to your site’s content:- /etc/nginx/sites-available/example.com
-
1 2 3 4 5 6 7 8 9 10 11server { listen 80; server_name example.com root /var/www/example.com; index index.html; location / { try_files $uri $uri/ =404; } }
Set up a new symlink to the
/etc/nginx/sites-enabled/directory to enable your configuration:sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Test NGINX
Test your configuration for errors:
sudo nginx -tReload the configuration:
sudo nginx -s reloadNavigate to your Linode’s domain name or IP address in a browser. You should see the NGINX default page displayed (or your own content, if you specified the path in the previous section).
Advanced Configuration
For more advanced configuration options, including security and performance optimizations and TLS setup, see our four-part series on NGINX:
- Part 1: Installation and Basic Setup
- Part 2: (Slightly More) Advanced Configurations
- Part 3: Enable TLS for HTTPS Connections
- Part 4: TLS Deployment Best Practices
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
Join our Community
Find answers, ask questions, and help others.
This guide is published under a CC BY-ND 4.0 license.