nginx default configuration file understand
Tags: devops, programming, linux, nginx
Published: 2023-09-22 06:55:35

# Where you will find default conf file and what will be it's name in linux?
**Ans:** `/etc/nginx/nginx.conf`
# Explanation of file
**Ans:** 
let's see what has in this file
run this command
`nano /etc/nginx/nginx.conf`

**You will get this output**

```
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

```

> let's explain line by line

**user nginx; :** This sets the user under which the Nginx worker processes will run. In this case, it's set to the "Nginx" user, it's enhance security by limiting the processes and permissions

**worker_processes auto; :** This will determine the number of worker process that Nginx will be handling for the incoming request. It will choose an automatic number of worker processes based on CPU.

**error_log /var/log/nginx/error.log notice; :** This will store your error log in the indicated location you can check here if you face any error during the run of the server.

**pid /var/run/nginx.pid;:** This file contains the master process ID. in a defined location.

**events { ... }:** In this section Nginx handle events like how Nginx handle connections and events like incoming request by default it has **1024** worker connections but you can change it as per your need.

**http { ... }:** This section actually handles all HTTP configurations for the server here we can include 
`include /etc/nginx/mime.types; ` which actually contain all types of file extensions like `.jpg .png .txt .html` ... etc. and 
`default_type application/octet-stream;` this section set default MIME type that doesn't have an explicitly defined type. 
`log_format main` here you can define the log format for every request.
`access_log /var/log/nginx/access.log main;` In this section, you can set the location and format for the access log file. It will keep every single request log with details. 

`sendfile on;` by doing this you are giving permission to send file system calls so that static files can be served efficiently. 

`keepalive_timeout 65;` In this section, you can set a timeout for keep-alive client connections. by default, it has 65 sec but you can set your own time.
`include /etc/nginx/conf.d/*.conf;` by doing this you can include additional configuration files from the `/etc/nginx/conf.d/` directory. Basically, when you think your configuration script going too big you can separate by doing this.


Thank you
You can find me on [linkedin](https://www.linkedin.com/in/nipuchakraborty/) connect with me to get more information like this.