Nginx File Configuration and Logs (Part 3)

Abdalrhmanalkraien
Javarevisited
Published in
4 min readFeb 9, 2022

Introduction:

after installing and going to Nginx directory /etc/nginx we can see Nginx file Like, nginx.config and sites-available file and other important files

each file of this has a role and task to make Nginx correct jobs.

in this article, I will explain important files to make correct Nginx and handle all requests without any problem.

all parts of Nginx Articles :

Nginx Files:

  • if we go to this path by terminal /etc/nginx we can see by default the following files

to access nginx directory. in Linux Os

root@ubuntu-16gb-hel1-1:/etc/nginx# cd /etc/nginx/

to see all files inside Nginx directory you can use the following command

root@ubuntu-16gb-hel1-1:/etc/nginx# ls

the output from the above command :

you can see here all the nginx file.

Add alt text

we will start with nginx.config:

  • etc/nginx.config:

all of the Nginx main configuration you can find it here ,

we can write our own configuration in this file and Nginx setup here.

we can write HTTP block here to define our configuration in all Nginx system.

in the next section will write our configuration and talk about each block in Nginx configuration

  • /etc/nginx/sites-available/

here we can write site domain and server block with configuration to specific application, and when reload Nginx nginx.config will read all files inside etc/sites-available/ folder.

but to enable this feature you must write the following configuration inside nginx.config

nginx by default will create the same file in sites-enabled with the same name.

include /etc/nginx/sites-enabled/fileName;
  • etc/nginx/sites-enabled/

when create a new directory you must link with configuration file by site-enable

you must linked sites-available/ with sites-enabled/ because /nginx.config need linked with /sites-enabled/ to enabled your configuration

  • /etc/nginx/snippets

if we have any repeated configuration between services we can include inside this file and share it with other configuration files.

okay now we know where we can make our configuration but where I can see my logs

when install nginx will created file in /var/log/nginx

inside this directory, we can find all logs from Nginx services.

okay let's go to the above directory and see what the logs provide services

to go to above directory you can use the following command:

cd /var/log/nginx/

and to see all files in /var/log/nginx write the following command:

ls

after that, you can see this file in output.

Add alt text

i will explain two important files in the logs section in this article.

  • /var/log/nginx/access.log

every request received to Nginx will record in this file like the following image.

Add alt text

we can changed this file from configuration file.

  • /var/log/nginx/error.log

each Nginx error will record here like the follwoing image.

Add alt text

i have one error just :)

Conclusion:

in this article, we know now what is the files job in Nginx and where we need each files in Nginx system.

and now we know where we can find our logs of each request in our system, with know where we can define our configuration.

Nginx is easy to use and I will explain about configuration in the next article

all parts of Nginx Articles :

don’t forget to clap on the articles and you can clap 50 times on each article.

references:

--

--

Abdalrhmanalkraien
Javarevisited

I am a Java Developer and DevOps Engineer. I used the latest Technology for build completed development or Deployment