Topic Title

Topic Title

Contents

1. Paragraph
2. Paragraph and Code
3. Table
4. Links
5. Files
6. More

Paragraph

blah blah blah blah blah blah blah blah blah

Paragraph and Code

blah blah blah blah blah blah blah blah blah

blah blah blah
blah blah blah

Table

pre pre pre pre  d
pre pre pre pre 
pre pre pre pre 

Links

#DOWNLOADLINK#

#DOWNLOADLINK#

Files

FILE TYPE - file
FILE TYPE - file

More


#LINK# - #LINK#

#LINK# - #LINK#

#LINK#

p

pb

code

nginx settings

defaults:

nginx config: /etc/nginx/nginx.conf

default site config: /etc/nginx/sites-available/default

default html dir: /var/www/html/

control:

check nginx status: (sudo systemctl status nginx)

check config for errors: (sudo nginx -t)

restart nginx: (sudo systemctl restart nginx)

also: restart, start, stop, enable, disable, reload


common:

ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

sudo certbot --nginx -d example.com

sudo nginx -t

sudo nginx -s reload

sudo systemctl restart nginx


config:

#test.example.com
server {
        server_name test.example.com;
        root /var/www/test.example.com/html;

        listen 80 ;
        listen [::]:80 ;

        # Redirect HTTP to HTTPS
        if ($scheme != "https") {
                return 301 https://$host$request_uri;
        }

        # SSL configuration
        listen [::]:443 ssl http2;      # Enable HTTP/2
        listen 443 ssl http2;           # Enable HTTP/2 for IP

        #SSL certificate
        #ssl_certificate /etc/letsencrypt/live/test.example.com/fullchain.pem; # managed by Certbot
        #ssl_certificate_key /etc/letsencrypt/live/test.example.com/privkey.pem; # managed by Certbot

        #SSL settings provided by Certbot
        #include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        #ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

        #note TLS is already enabled in options-ssl-nginx.cong above, enabling it below will cause a double declaration error
        #ssl_protocols TLSv1.2 TLSv1.3; # Enable TLS protocols

        #Security
        server_tokens off;

        # Gzip
        gzip on;
        gzip_comp_level 5;
        gzip_min_length 256;
        #text/html is already declared to compress with gzip globally, declaring it here will cause dougble declareation error.
        gzip_types text/html text/plain text/css application/javascript application/json;

        # Logging
        access_log /var/www/test.example.com/html/access.log;
        error_log /var/www/test.example.com/html/error.log;

        # Error pages
        error_page 404 /404.html;
        error_page 500 502 503 504 /500.html;

        # Location
        index index.php;
        location / {
                if ($scheme != "https") {
                        return 301 https://$host$request_uri;
                }
                try_files $uri $uri/ /index.php?$args;
        }


        # PHP
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        }
}

        

Setting up a new subdomain, step by step, manually

create a new subdomain folder with a full url path that is going to handle all the files for the subdomain. Then create an html folder inside of it.

sudo mkdir subdomain.n77.nl
sudo mkdir subdomain.n77.nl/html

create a new nginx subdomain config file to use with this subdomain

sudo nano /etc/nginx/sites-available/subdomain.n77.nl

enable the site by putting a link from sites-available to sites-enabled

sudo ln -s /etc/nginx/sites-available/subdomain.n77.nl /etc/nginx/sites-enabled/subdomain.n77.nl

reload and apply new subdomain nginx config without restarting the server and terminating existing sessions

sudo nginx -s reload or sudo systemctl reload nginx

setup permissions on the html folder

sudo chmod 755 /var/www/subdomain.n77.nl/html

create a simple index.htm in the root html folder of the subdomain

sudo echo 'Sample Page

Hello, World!

' | sudo tee /var/www/subdomain.n77.nl/html/index.htm > /dev/null

Security

Top 25 Nginx Web Server Best Security Practices
Nginx Secure Web Server

Official Links

# 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.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure