title

Hana,这题本质是:在 openEuler 上用 Nginx/Apache 配置基于不同端口的虚拟主机。下面我给你一份可以直接写进实验报告的答案模板,包含:配置步骤、源代码、验证命令,以及截图位置说明。

我不能替你伪造浏览器截图,但你按步骤做完后,把对应截图贴进去就行啦 (。・ω・。)

下面以 Nginx 为例。


openEuler 搭建基于不同端口的虚拟主机

一、实验要求

在 openEuler 系统中搭建两个基于不同端口的网站:

| 网站 | 端口 | 网站根目录 | 首页文件内容 |

|—|—:|—|—|

| 网站 1 | 8080 | /mnt/web | 包含姓名拼音全称 |

| 网站 2 | 8088 | /mnt/dport | 包含姓名拼音全称 |

本人姓名拼音全称:Xu Yuanyuan


二、安装 Nginx

1
2
3

sudo dnf install -y nginx

启动并设置开机自启:

1
2
3
4
5

sudo systemctl start nginx

sudo systemctl enable nginx

查看 Nginx 状态:

1
2
3

systemctl status nginx


三、创建两个网站根目录

1
2
3
4
5

sudo mkdir -p /mnt/web

sudo mkdir -p /mnt/dport


四、配置两个网站首页文件

1. 配置 /mnt/web/index.html

1
2
3

sudo vi /mnt/web/index.html

添加如下内容:

1
2
3
4
5
6
7

<!DOCTYPE html>

<html>

<head>

1
2


8080 Port Website
1
2
3
4
5
6


</head>

<body>

Welcome to 8080 Port Website

1
2


This is the website root directory: /mnt/web

1
2


Name: Xu Yuanyuan

1
2
3
4
5
6


</body>

</html>

2. 配置 /mnt/dport/index.html

1
2
3

sudo vi /mnt/dport/index.html

添加如下内容:

1
2
3
4
5
6
7

<!DOCTYPE html>

<html>

<head>

1
2


8088 Port Website
1
2
3
4
5
6


</head>

<body>

Welcome to 8088 Port Website

1
2


This is the website root directory: /mnt/dport

1
2


Name: Xu Yuanyuan

1
2
3
4
5
6


</body>

</html>


五、修改 Nginx 配置文件

编辑 Nginx 主配置文件:

1
2
3

sudo vi /etc/nginx/nginx.conf

http { } 配置块中添加以下两个 server 配置:

1
2
3

server {

listen 8080;

1
2


server_name localhost;

1
2
3
4




root /mnt/web;

1
2


index index.html;

1
2
3
4




location / {

1
2


try_files $uri $uri/ =404;

1
2


}

1
2
3
4
5
6
7
8


}



server {

listen 8088;

1
2


server_name localhost;

1
2
3
4




root /mnt/dport;

1
2


index index.html;

1
2
3
4




location / {

1
2


try_files $uri $uri/ =404;

1
2


}

1
2
3
4


}

完整效果示例:

1
2
3

http {

include /etc/nginx/mime.types;

1
2


default_type application/octet-stream;

1
2
3
4




server {

1
2


listen 8080;

1
2


server_name localhost;

1
2
3
4




root /mnt/web;

1
2


index index.html;

1
2
3
4




location / {

1
2


try_files $uri $uri/ =404;

1
2


}

1
2


}

1
2
3
4




server {

1
2


listen 8088;

1
2


server_name localhost;

1
2
3
4




root /mnt/dport;

1
2


index index.html;

1
2
3
4




location / {

1
2


try_files $uri $uri/ =404;

1
2


}

1
2


}

1
2
3
4


}


六、开放防火墙端口

如果系统开启了防火墙,需要开放 8080 和 8088 端口:

1
2
3
4
5
6
7

sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent

sudo firewall-cmd --zone=public --add-port=8088/tcp --permanent

sudo firewall-cmd --reload

查看端口是否开放:

1
2
3

sudo firewall-cmd --list-ports


七、检查配置并重启 Nginx

检查 Nginx 配置文件是否正确:

1
2
3

sudo nginx -t

如果显示类似下面内容,说明配置正确:

1
2
3
4
5

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

重启 Nginx:

1
2
3

sudo systemctl restart nginx

查看监听端口:

1
2
3

sudo ss -tunlp | grep nginx

应该可以看到 Nginx 正在监听 80808088 端口。


八、实验截图

截图 1:Nginx 配置文件截图

截图内容应包含 /etc/nginx/nginx.conf 中新增或修改的两个 server 配置块。

截图粘贴处:

在这里粘贴 /etc/nginx/nginx.conf 配置截图。


截图 2:访问 8080 端口网站结果

浏览器访问:

1
2
3

http://服务器IP地址:8080

如果是在本机浏览器中访问,也可以使用:

1
2
3

http://localhost:8080

页面应显示:

1
2
3
4
5
6
7

Welcome to 8080 Port Website

This is the website root directory: /mnt/web

Name: Xu Yuanyuan

截图粘贴处:

在这里粘贴浏览器访问 http://服务器IP地址:8080 的结果截图。


截图 3:访问 8088 端口网站结果

浏览器访问:

1
2
3

http://服务器IP地址:8088

如果是在本机浏览器中访问,也可以使用:

1
2
3

http://localhost:8088

页面应显示:

1
2
3
4
5
6
7

Welcome to 8088 Port Website

This is the website root directory: /mnt/dport

Name: Xu Yuanyuan

截图粘贴处:

在这里粘贴浏览器访问 http://服务器IP地址:8088 的结果截图。


九、实验结论

通过本次实验,在 openEuler 系统中成功使用 Nginx 搭建了两个基于不同端口的虚拟主机。

其中,8080 端口网站根目录为 /mnt/web,8088 端口网站根目录为 /mnt/dport

两个网站均能通过浏览器正常访问,并且首页内容中均包含本人姓名拼音全称 Xu Yuanyuan,满足实验要求。

Preparing answer template

I’m considering how to structure the answer with steps, source code, and placeholders for screenshots. I’ll include instructions on where to insert screenshots and ensure the response is clear and honest.