md/nginx
2024-11-03 16:44:20 -06:00
..
resources added nginx 2024-11-03 16:44:20 -06:00
README.md added nginx 2024-11-03 16:44:20 -06:00

Nginx Server

Walkthrough of installing Nginx Webserver

Table of Contents

Step One - Installing Nginx

First we need to install Nginx.
sudo apt update
sudo apt install nginx

If you have UFW on you should allow HTTP with:
sudo ufw allow 'Nginx Full'

Nginx should now be fully operational, to check.
sudo systemctl enable nginx - To set up nginx to start up on reboot.
sudo systemctl start nginx
sudo systemctl status nginx - Should give you the status of the server.

Go to your ip address to see the nginx default page. Next, we'll configure our server.

Step 2 - Configuring Our Server

Now that nginx is install and running, we should now configure our server. Here are the files we normally edit.
/var/www/html Typically you'll remove the default and create a folder like /var/www/mysite.com
/etc/nginx: The Nginx configuration directory. All of the Nginx configuration files reside here.
/etc/nginx/nginx.conf:The main Nginx configuration file. This can be modified to make changes to the Nginx global configuration.

/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 refactoring into snippets.

/etc/nginx/sites-available/mysite.com:The directory where per-site server blocks can be stored. Nginx will not use the configuration files found in this directory unless they are linked to the sites-enabled directory. Typically, all server block configuration is done in this directory, and then enabled by linking to the other directory.
/etc/nginx/sites-enabled/mysite.com: he directory where enabled per-site server blocks are stored. Typically, these are created by linking to configuration files found in the sites-available directory.

You can link those by:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Here are some samples of files you may encounter, and settings you may set.
/etc/nginx/nginx.conf
/etc/nginx/sites-available
Digital Ocean - Server Blocks
Rate Limiting With Nginx

Step 3 - Troubleshooting Your Server

/var/log/nginx/access.log: Every request to your web server is recorded in this log file unless Nginx is configured to do otherwise.
/var/log/nginx/error.log: Any Nginx errors will be recorded in this log.

Step 4 - Setting up HTTPS with Certbot

Now with Nginx configured and running we should set up HTTPS with Certbot.
sudo apt update
sudo apt install snapd
sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

sudo certbot --nginx Fill out the questions about domain name email etc.

sudo nginx -t
sudo systemctl reload nginx

Now you should have a fully functional HTTPS server.

Resources

I found these resources helpful.

Digital Ocean - Nginx
Digital Ocean - Let's Encrypt
Digital Ocean - Server Blocks
Rate Limiting With Nginx
Youtube
YouTube