Welcome 🎉

logo

ReactLMS

Search
Light Mode
Contact Us

5 min to read

Contact us

No results for your search.
Sorry, an unexpected error occurred

Introduction


For a Web Server, nginx's job is to run static/dynamic content. And which content of the system to run will be determined in the Configuration files.

📘
The nginx config file will have the extension .conf


Access


The nginx config file is usually located in the /etc/nginx/ directory, use the cd command to access the nginx folder.

cd /etc/nginx






Next, we use the ls command to list all files in the application.

ls -lh






Assume that the result of the file list is as follows

# drwxr-xr-x 2 root root 4.0K Apr 21  2020 conf.d
# -rw-r--r-- 1 root root 1.1K Feb  4  2019 fastcgi.conf
# -rw-r--r-- 1 root root 1007 Feb  4  2019 fastcgi_params
# -rw-r--r-- 1 root root 2.8K Feb  4  2019 koi-utf
# -rw-r--r-- 1 root root 2.2K Feb  4  2019 koi-win
# -rw-r--r-- 1 root root 3.9K Feb  4  2019 mime.types
# drwxr-xr-x 2 root root 4.0K Apr 21  2020 modules-available
# drwxr-xr-x 2 root root 4.0K Apr 17 14:42 modules-enabled
# -rw-r--r-- 1 root root 1.5K Feb  4  2019 nginx.conf
# -rw-r--r-- 1 root root  180 Feb  4  2019 proxy_params
# -rw-r--r-- 1 root root  636 Feb  4  2019 scgi_params
# drwxr-xr-x 2 root root 4.0K Apr 17 14:42 sites-available
# drwxr-xr-x 2 root root 4.0K Apr 17 14:42 sites-enabled
# drwxr-xr-x 2 root root 4.0K Apr 17 14:42 snippets
# -rw-r--r-- 1 root root  664 Feb  4  2019 uwsgi_params
# -rw-r--r-- 1 root root 3.0K Feb  4  2019 win-utf






In those files, we will find a file named nginx.conf, this is the main config file of nginx.

We will use the cat command to read this config file.

cat nginx.conf






After running the above command, we will see the following content

# user www-data;

# worker_processes auto;

# pid /run/nginx.pid;

# include /etc/nginx/modules-enabled/*.conf;


# events {

#     worker_connections 768;

#     # multi_accept on;

# }


# http {


#     ##

#     # Basic Settings

#     ##


#     sendfile on;

#     tcp_nopush on;

#     tcp_nodelay on;

#     keepalive_timeout 65;

#     types_hash_max_size 2048;

#     # server_tokens off;


#     # server_names_hash_bucket_size 64;

#     # server_name_in_redirect off;


#     include /etc/nginx/mime.types;

#     default_type application/octet-stream;


#     ##

#     # SSL Settings

#     ##


#     ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE

#     ssl_prefer_server_ciphers on;


#     ##

#     # Logging Settings

#     ##


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

#     error_log /var/log/nginx/error.log;


#     ##

#     # Gzip Settings

#     ##


#     gzip on;


#     # gzip_vary on;

#     # gzip_proxied any;

#     # gzip_comp_level 6;

#     # gzip_buffers 16 8k;

#     # gzip_http_version 1.1;

#     # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;


#     ##

#     # Virtual Host Configs

#     ##


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

#     include /etc/nginx/sites-enabled/*;

# }



# #mail {

# #    # See sample authentication script at:

# #    # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript

# # 

# #    # auth_http localhost/auth.php;

# #    # pop3_capabilities "TOP" "USER";

# #    # imap_capabilities "IMAP4rev1" "UIDPLUS";

# # 

# #    server {

# #        listen     localhost:110;

# #        protocol   pop3;

# #        proxy      on;

# #    }

# # 

# #    server {

# #        listen     localhost:143;

# #        protocol   imap;

# #        proxy      on;

# #    }

# #}






There seems to be a lot of information in the config and it seems difficult to understand, but don't worry, we will create a new config file and start learning.


Create a new file


To create a new file, first we need to rename the old file to backup when necessary.

sudo mv nginx.conf nginx.conf.backup






After running the above command, the nginx.conf config file has been renamed to nginx.conf.backup

Next, we will create a new file with the following command

sudo touch nginx.conf






⚠️
In fact, we do not recommend editing the original nginx config file unless you fully understand it.



Read more
On This Page