Environment Setup
Disable conflicting security services and install the necessary packages using the DNF package manager:
dnf install nginx httpd-tools -y
Configure local DNS resolution on the client machine by adding the following entry to the C:\Windows\System32\drivers\etc\hosts file:
10.0.0.10 www.openlab.com
Main Domain Configuration
Generate the document root and the landing page for the primary domain:
mkdir -p /var/web/openlab_root
echo '<h1>welcome to openlab!!!</h1>' > /var/web/openlab_root/index.html
Append the following server block to the Nginx configuration:
server {
listen 80;
server_name www.openlab.com;
root /var/web/openlab_root;
}
Apply the configuration changes and start the service:
systemctl enable --now nginx
Teaching Materials Sub-directory
Create the directory structure and HTML file for the educational content:
mkdir -p /var/web/teaching_assets
echo 'Teaching Data' > /var/web/teaching_assets/index.html
Insert a location block within the existing 80 port server block to handle the /data path:
location /data {
alias /var/web/teaching_assets;
index index.html;
}
Reload the service to apply updates:
systemctl reload nginx
Student Information Portal with Access Control
Set up the directory for student data and generate the authentication file for users song and tian:
mkdir -p /var/web/pupil_data
echo 'Student Info' > /var/web/pupil_data/index.html
htpasswd -cb /etc/nginx/.htpasswd song 123456
htpasswd -b /etc/nginx/.htpasswd tian 654321
Add the restricted location block to the Nginx server configuration:
location /student {
alias /var/web/pupil_data;
index index.html;
auth_basic "Authentication Required";
auth_basic_user_file /etc/nginx/.htpasswd;
}
Reload the Nginx service:
systemctl reload nginx
Encrypted Payment Portal via HTTPS
Create the directory and index file for the payment system:
mkdir -p /var/web/payment_portal
echo 'Payment System' > /var/web/payment_portal/index.html
Generate the SSL private key and self-signed certificate:
mkdir -p /etc/nginx/ssl
openssl genrsa -aes256 -passout pass:secret -out /etc/nginx/ssl/finance.key 2048
openssl req -utf8 -new -key /etc/nginx/ssl/finance.key -x509 -days 365 -out /etc/nginx/ssl/finance.crt -passin pass:secret
cp /etc/nginx/ssl/finance.key /etc/nginx/ssl/finance.key.bak
openssl rsa -in /etc/nginx/ssl/finance.key.bak -out /etc/nginx/ssl/finance.key -passin pass:secret
Define a new server block listening on port 443 for encrypted traffic:
server {
listen 443 ssl;
server_name www.openlab.com;
ssl_certificate /etc/nginx/ssl/finance.crt;
ssl_certificate_key /etc/nginx/ssl/finance.key;
location /money {
alias /var/web/payment_portal;
index index.html;
}
}
Restart the Nginx service to activate the SSL configuration:
systemctl restart nginx