Skip to content

Nginx Configuration

Opening Nginx Configuration

cd /etc/nginx
ls
cat nginx.conf

Rename the file for backup

sudo mv nginx.conf nginx.conf.backup

Create a new configuration file

sudo touch nginx.conf

Open configuration file using nano editor

sudo nano nginx.conf

Write this configuration in nginc.conf for serving text content.

events {

}

http {

    server {

        listen 80;
        server_name nginx-handbook.test;

        return 200 "Bonjour, mon ami!\n";
    }

}

Test the configuration file for syntax problem

sudo nginx -t

Restart nginx after writing the configuration file

sudo service nginx restart

Writing configuration for serving static content

First download the files from git and store it in srv directory

  • The /srv directory is meant to contain site-specific data which is served by this system.
  • Now cd into this directory and clone the code repository that comes with this book:
cd /srv
sudo git clone https://github.com/fhsinchy/nginx-handbook-projects.git

Update the nginx.conf file for serving static content

events {

}

http {

    server {

        listen 80;
        server_name nginx-handbook.test;

        root /srv/nginx-handbook-projects/static-demo;
    }

}