...
Creating web directory for each host
Code Block $ sudo mkdir -p /var/www/html/example.com/public_html #The above directory is owned by root user. We need to change the ownership to the regular user $ sudo chown -R $USER:$USER /var/www/html/example.com/public_html $ sudo chmod -R 755 /var/www/html/ #Here the $USER refers to you, the currently logged in user
Creating demo page for each Host
Code Block $ sudo nano /var/www/html/example.com/public_html/index.html
Add the following lines
Code Block <html> <head> <title>www.example.com</title> </head> <body> <h1>Hello! this page is to test for the static website</h1> </body> </html>
Create configuration file for each host
Code Block language actionscript3 $ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com.conf $ sudo nano /etc/nginx/sites-available/example.com.conf output: # Default server configuration # server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html/example.com/public_html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name example.com www.example.com; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } #Edit line 27 and 32 accordingly in your terminal
Enable Nginx Server block
Code Block $ sudo rm /etc/nginx/sites-enabled/default $ sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/ $ sudo systemctl restart nginx
Test Nginx Server block
Code Block $ sudo nano /etc/hosts #Add all your virtual domain like below. output: [...] 192.168.225.24 example.com [...] #we do this beacuse this is your domain and we'll need to point it to the localhost server
The We’re working on a script that will do all of this manual work for you → script.sh (still to come) please configure manually for now, we are working on automating this process by writing a simple script. It should be available soonn soon
to execute this
Name it something like:
script.sh
.Make it executable:
sudo chmod 755 script.sh
Run it:
sudo ./script.sh example.com
...