Nginx Quick References

This page shows how to create an Nginx site.

1. Choose an Nginx template.


To host local files create the directories to for site and using these commands.

Create directory
mkdir -p /var/www/
Create index.html file
echo "<h1>Hello world</h1>" > /var/www/
Create a phpinfo page
echo "<?php phpinfo(); ?>" > /var/www/

Then, create the Nginx .conf file.

nano /etc/nginx/sites-available/
HTML/PHP Nginx Template file
server {
    listen 80;
    listen [::]:80;

    root /var/www/;
    index index.html index.htm index.nginx-debian.html index.php;


    location / {
            try_files $uri $uri/ =404;

    # pass PHP scripts to FastCGI server
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

Reverse Proxy

Create a new site called that is a reverse proxy for a hosted application

  • Replace the port number in proxy_pass http://localhost:8888;

nano /etc/nginx/sites-available/
Reverse Proxy Nginx Template file
server {
    listen 80;


    location / {
        proxy_pass http://localhost:8888;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

2. Enable or Disable an Nginx site

Enable an Nginx site

  • Use ln -s to create a symbolic link to sites-enabled

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Disable an Nginx site

  • You can remove or delete the symbolic link to disable a site or remove an invalid configuration.

rm /etc/nginx/sites-enabled/

Verify if site is enabled

  • Perform a directory listing of sites-enabled to determine if it contains a link to a config

ls -lh /etc/nginx/sites-enabled/

3. Verify and Apply Configuration

Check for configuration issues

nginx -t

Apply Config Changes

  • Restart Nginx to apply config changes using systemctl

systemctl restart nginx
  • Check the status of Nginx using systemctl

systemctl status nginx