To install and configure Nginx on Ubuntu Linux 18.04 LTS, follow these steps:
sudo apt update sudo apt install nginx
sudo systemctl start nginx
To configure Nginx, you will need to edit the configuration files in the /etc/nginx
directory. The main configuration file is nginx.conf
, which controls the global settings for Nginx.
Within the /etc/nginx
directory, there is also a sites-available
directory that contains configuration files for individual websites. To enable a website, you will need to create a configuration file in this directory and then create a symbolic link to it in the sites-enabled
directory.
For example, to enable a website with the domain name example.com
, you would create a configuration file called example.com
in the sites-available
directory and then run the following command:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
server { listen 80; server_name example.com; root /var/www/example.com; location / { try_files $uri $uri/ =404; } }
This configuration file tells Nginx to listen on port 80, to use the domain name example.com
, and to serve files from the /var/www/example.com
directory.
sudo systemctl restart nginx