NGINX
NGINX - SUBDOMAINS AND SERVER BLOCKSPermalink
- cf : tuto digital ocean
- cf : tuto linuxize / nginx
- cf : tuto linuxize / blocks
SETUP NGINXPermalink
install nginxPermalink
sudo apt update
sudo apt install nginx
check statusPermalink
sudo systemctl status nginx
check possible configsPermalink
sudo ufw app list
for http and httpsPermalink
sudo ufw allow 'Nginx Full'
also
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS’
MANAGE NGINX SERVICESPermalink
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
if you want to disable the Nginx service to start at bootPermalink
sudo systemctl disable nginx
sudo systemctl enable nginx
-
All Nginx configuration files are located in the
/etc/nginx
directory. -
The main Nginx configuration file is
/etc/nginx/nginx.conf
-
To make Nginx configuration easier to maintain it is recommended to create a separate configuration file for each domain. You can have as many server block files as you need.
-
Nginx server block files are stored in
/etc/nginx/sites-available
directory. The configuration files found in this directory are not used by Nginx unless they are linked to the /etc/nginx/sites-enabled directory. -
To activate a server block you need to create a symlink (a pointer) from the configuration file sites in a
sites-available
directory to thesites-enabled
directory. -
It is recommended to follow the standard naming convention, for example if your domain name is mydomain.com then your configuration file should be named
/etc/nginx/sites-available/mydomain.com.conf
-
The
/etc/nginx/snippets
directory contains configuration snippets that can be included in the server block files. If you use repeatable configuration segments then you can refactor those segments into snippets and include the snippet file to the server blocks. -
Nginx log files (
access.log
anderror.log
) are located in the/var/log/nginx
directory. It is recommended to have a different access and error log files for each server block. -
You can set your domain document root directory to any location you want. The most common locations for webroot include:
/home/<user_name>/<site_name>
/var/www/<site_name>
/var/www/html/<site_name>
/opt/<site_name>
DIRECTORIES FOR BLOCKS OF CODEPermalink
make a subdirectory for each subdomain on droplet (-p : make parent dir if needed )Permalink
sudo mkdir -p /var/www/apiviz-preprod-api.co-demos.com/
sudo mkdir -p /var/www/apiviz-api.co-demos.com/
…
Change group owner of the directoryPermalink
cf : https://askubuntu.com/questions/488485/allowing-a-group-read-write-access-to-a-directory
sudo usermod -aG adminsys www-data
Change group owner of the directoryPermalink
cf : https://askubuntu.com/questions/30629/how-can-i-recursively-change-the-permissions-of-files-and-directories
sudo chgrp -R adminsys /var/www
Give write permission to the group / ug == user + groupPermalink
sudo chmod -R ug+rw /var/www