# Nginx Server Walkthrough of installing Nginx Webserver ## Table of Contents - [Step One - Installing Nginx](#step-one---installing-nginx) - [Step Two - Configuring our Server](#step-2---configuring-our-server) - [Step Three - Troubleshooting your Server](#step-3---troubleshooting-your-server) - [Step Four - OPTIONAL - Setting up HTTPS with Certbot](#step-4---setting-up-https-with-certbot) - [Resources](#resoureces) ### 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](./defaults/nginx.conf)
[/etc/nginx/sites-available](./defaults/nginx.conf)
[Digital Ocean - Server Blocks](./resources/DigitalOcean_ServerBlocks.md)
[Rate Limiting With Nginx](./resources/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 ](./resources/DigitalOcean_Nginx.md)
[Digital Ocean - Let's Encrypt](./resources/DigitalOcean_LetsEncrypt.md)
[Digital Ocean - Server Blocks](./resources/DigitalOcean_ServerBlocks.md)
[Rate Limiting With Nginx](./resources/Rate_Limiting_With_Nginx)
[![Youtube](https://i.ytimg.com/vi/HaY8QB5kkGw/hqdefault.jpg)](https://youtu.be/HaY8QB5kkGw?si=9k44i9hon35KsaYp)
[![YouTube](https://i.ytimg.com/vi/-lrSPJTeGhQ/hqdefault.jpg)](https://www.youtube.com/watch?v=-lrSPJTeGhQ)