serversetups/nginx-setup.md

63 lines
1.1 KiB
Markdown

# Nginx Setups
Sources:
[Nginx Beginners Guide](http://nginx.org/en/docs/beginners_guide.html)
[Nginx Config Example](https://www.nginx.com/resources/wiki/start/topics/examples/full/)
## 1. Installation
If not installed, execute this:
```bash
sudo apt install nginx certbot python3-certbot-nginx
```
## 2. create nginx config
To create a config execute:
```bash
touch /etc/nginx/sites-available/[SUBDOMAIN].[DOMAIN]
```
Copy from [the default config](./nginx-configs/default)
And paste it after executing:
```bash
nano /etc/nginx/sites-available/[SUBDOMAIN].[DOMAIN]
```
Dont forget to replace `[PLACEHOLDERS]`
Softlink to sites-enabled
```bash
sudo ln -s /etc/nginx/sites-available/[SUBDOMAIN].[DOMAIN] /etc/nginx/sites-enabled/
```
## 3. Check and restart nginx
Test the new config with this command:
```bash
sudo nginx -t
```
If successful execute
```bash
sudo systemctl restart nginx
```
## 4. Get https certificate
In Cloudflare or another dns manager add an a record to the ip for creating a sub domain.
After that certify the subdomain with this command.
```bash
sudo certbot --nginx -d [SUBDOMAIN].[DOMAIN]
```