Important NGINX Directories and Files for Easy Referencing

Important NGINX Directories and Files for Easy Referencing
Photo by Taylor Vick / Unsplash

When it comes to running a web server for all of my online projects, NGINX is the first that comes to mind for me. By default, it follows my guidelines of running a piece of software – meaning that the software is security-minded, performance-driven, and honestly, really easy to manage all the aspects of it.

NGINX is most likely the most popular web server software in the world, and it's well known for being the backbone of some of the biggest sites on the internet to date. It is a lightweight choice that can be used as either a web server and or reverse proxy, and pretty much fits most people's needs without too much configuration and setup.


[ Don't Forget! Installing NGINX for your web server. ]

In the following guide, I will be walking you through the important NGINX directories and files which you may need to know about and or reference in the future. This guide is mainly a quick reference.

Content

  • /var/www/html/: The actual website content directory of a default NGINX installation, which by default only consists of only the default NGINX. The default path is served out of the /var/www/html directory, but this can be changed to whatever you want by changing configuration files.

Server Configuration

  • /etc/nginx: This is the NGINX installation directory. All of the NGINX application and configuration files are here.
  • /etc/nginx/nginx.conf: This is the main NGINX configuration file. This can be modified to make changes to the NGINX application and configuration.
  • /etc/nginx/sites-available/: The default directory where different website server blocks should be stored. NGINX will not use the configuration files found in this directory unless they are linked to the sites-enabled directory by default. Almost all of the time, all server block configuration is done in this directory, and then enabled by linking to the sites-enabled directory.
  • /etc/nginx/sites-enabled/: The directory where different enabled website server blocks are stored. Almost all of the time, these are created by linking to configuration files found in the sites-available directory.
  • /etc/nginx/snippets: This directory contains configuration fragments that can be included elsewhere in the NGINX configuration. Potentially repeatable configuration segments are good candidates for reusing in different website configuration files.

Server Logs

  • /var/log/nginx/access.log: Every request made by the webserver is recorded in this log file for reference if needed.
  • /var/log/nginx/error.log: Any errors that may happen with NGINX will be recorded in this log. You can reference the errors in the log to solve issues.\

Default Configuration File

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # proxy_pass http://localhost:8080;
                # proxy_http_version 1.1;
                # proxy_set_header Upgrade $http_upgrade;
                # proxy_set_header Connection 'upgrade';
                # proxy_set_header Host $host;
                # proxy_cache_bypass $http_upgrade;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        # include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#              try_files $uri $uri/ =404;
#       }