Tutorial for Nginx server for linux https://nginx.org/en/
Installation:
- sudo apt update
- sudo apt install nginx -y
Once the installation is complete, start Nginx and enable it to run on boot:
- sudo systemctl start nginx
- sudo systemctl enable nginx
Adjust your firewall settings (if necessary)
if you have firewall enabled, then allow HTTP and HTTPS traffic:
- sudo ufw allow 'Nginx Full'
Verify Nginx Installation
- sudo systemctl status nginx
Now open on browser to see default welcome page for nginx server by:
- sudo nano /var/www/html/error-pages/403.html
- sudo nano /var/www/html/error-pages/404.html
- sudo nano /etc/nginx/sites-available/default or sudo nano /etc/nginx/nginx.conf
error_page 403 /error-pages/403.html;
error_page 404 /error-pages/404.html;
location = /error-pages/403.html {
root /var/www/html;
internal;
}
location = /error-pages/404.html {
root /var/www/html;
internal;
}
- error_page 404 or 403 tells Nginx to display your custom 404.html and 403.html page from the /var/www/html/error-pages directory whenever a 404 and 403 error occurs.
- location = /error-pages/404.html or /error-pages/404.html {...} ensures that the custom 404.html or 403.html file is served correctly when a 404 error and 403 error occurs and it is handled internally.
- sudo systemctl restart nginx
- sudo systemctl reload nginx
-
create shell scripting file
-
Folder name create_user.sh #!/bin/bash
if [ -z "$1" ]; then echo "Please provide a username." exit 1 fi USERNAME=$1 USERDIR="/home/$USERNAME/www" sudo useradd -m $USERNAME sudo mkdir -p $USERDIR sudo chown -R $USERNAME:$USERNAME /home/$USERNAME echo "Welcome to $USERNAME's website" | sudo tee $USERDIR/index.html sudo chmod -R 755 /home/$USERNAME echo "User $USERNAME created with default website folder and index.html file."
location ~^/~([a-zA-Z0-9_-]+)(.*)
{
alias /home/$1/www$2;
index index.html index.htm;
autoindex on;
fancyindex on;
fancyindex_css_href "/fancyindex.css";
}
- ./create_user stephen
- ls /home
write google.ldh.in/~stephen on browser