CentOS is pretty comfortable OS which gives extra support to developers, especially such as brew yum etc, over Ubuntu.
Step 1: Installing NGINX on OS
a. We need to add the CentOS EPEL package so that we can install NGINX.
sudo amazon-linux-extras install epel
note: If you are experiencing any issues follow this link
b. Now that our repository is installed on the server, we can now use yum to install NGINX, like so:
sudo yum -y install nginx
c. Start NGINX.
sudo systemctl start nginx.service
Step 2: Create a new user for the webspace
Before doing anything, we need to create a UNIX user for your web space.
a. Add the username
sudo useradd phoenix
b. Add the password
sudo passwd phoenix
Step 3: Create a new user for the webspace
Now it’s time to get it working for your domain. We need to create the directory that will act as the DocumentRoot for this website. It is a good idea to follow a standard naming convention if you are hosting multiple websites
a. Create a directory
sudo mkdir -p /var/www/nginxsite.com/public_html
b. Open the file
sudo vim /var/www/nginxsite.com/public_html/index.html
c. Enter the username, password
sudo chown -R phoenix:phoenix /var/www/nginxsite.com/public_html
d. Use the chmod command
sudo chmod 755 /var/www/nginxsite.com/public_html
e. Enter two commands to create directory available and enabled
sudo mkdir /etc/nginx/sites-available
sudo mkdir /etc/nginx/sites-enabled
f. Open the conf file
vim /etc/nginx/nginx.conf
vim /etc/nginx/sites-available/nginxsite.com.conf
vim /etc/nginx/sites-enabled/nginxsite.com.conf
g. list the files
ls -s /etc/nginx/sites-available/nginxsite.com.conf /etc/nginx/sites-enabled/nginxsite.com.conf(OR)> cd sites-enabled
> sudo ln -s ../sites-available/nginxsite.conf .
> ls -l
Step 4: Hurray! It’s time to start your NGINX server
a. Restart the Nginx service
sudo systemctl restart nginx.service
b. Open the conf file and make changes as per your requirement
vim /etc/nginx/nginx.conf
c. Restart the service
sudo systemctl start nginx.service
Free hacks for you :
#hack 1: It is highly recommended to turn of Apache on your OS, before proceeding to install NGINX.
#hack 2: It’s good practise to test your NGINX server on every change that you make in *.conf file with this command,
sudo service nginx -t
#hack 3: To see the running process(on respective ports) run the below command
sudo netstat -lntup
#hack 4: Check logs
sudo tail -f /var/log/nginx/error.logsudo tail -f /var/log/nginx/access.log
Reference links:
1. https://stackoverflow.com/questions/42303401/nginx-will-not-start-address-already-in-use
2. https://stackoverflow.com/questions/32489902/starting-nginx-gives-org-freedesktop-policykit1-error
3. Remove trailing slash issue : https://serverfault.com/a/870620/455085
4. Install & renew free SSL certificates : https://medium.com/@dearsikandarkhan/get-free-ssl-certificates-and-configure-https-f710dbc5e269
Happy exploration.
Learn — Grow — Glow
Reach me at LinkedIn