Command:
sudo mkdir -p /var/www/port8080site/html
sudo chmod -R 755 /var/www/port8080site
Explanation: This step sets up a directory where the site’s content will reside. Setting the appropriate permissions ensures that the web server can serve the content properly.
Command:
sudo nano /var/www/port8080site/html/index.html
Content Example:
<!DOCTYPE html> <html> <head> <title>Welcome to Port 8080 Site!</title> </head> <body> <h1>Success! You are viewing the site on port 8080!</h1> </body> </html>
Explanation: This file serves as the landing page for the new site. Students can use this to verify that Nginx is correctly serving the site.
Command:
sudo nano /etc/nginx/sites-available/port8080site
Configuration Example:
server { listen 8080; server_name localhost; root /var/www/port8080site/html; index index.html; location / { try_files $uri $uri/ =404; } }
Explanation: This configuration tells Nginx to listen on port 8080 and serve content from the /var/www/port8080site/html directory. The server_name directive is set to localhost for local testing.
Command:
sudo ln -s /etc/nginx/sites-available/port8080site /etc/nginx/sites-enabled/
Explanation: Enabling the site by creating a symbolic link in sites-enabled allows Nginx to serve this configuration. The role of the sites-available and sites-enabled directories in managing multiple sites should be explained.
Command:
sudo nginx -t
Explanation: Before applying changes, it’s crucial to ensure the configuration syntax is correct. This command helps catch errors that could prevent Nginx from reloading properly.
Command:
sudo systemctl reload nginx
Explanation: Reloading Nginx will apply the new configuration, making the site available on port 8080 without disrupting existing connections.
Command: Open a web browser or use curl to access the site:
curl http://localhost:8080
Explanation: Visiting http://localhost:8080 should display the index.html content. Discuss how different ports can be used to run multiple sites on the same server and the implications of using non-standard ports.
Command:
sudo unlink /etc/nginx/sites-enabled/port8080site
sudo systemctl reload nginx
Explanation: This demonstrates how to disable a site by removing the symbolic link, making it easier to manage which sites are active.