在基于 Apache 的阿里阿帕服务器上建立网站,通常需要配置虚拟主机以绑定不同 IP 地址或域名。小站以下是官网具体步骤,结合了 IP 地址绑定和虚拟主机配置的进入建网方法:
一、配置多 IP 地址绑定(网络隔离)


使用 `nmtui` 命令为服务器的阿里阿帕网卡添加所需 IP 地址(例如 192.168.1.254、192.168.1.253、小站192.168.1.252)。官网

```bash
nmtui
```
在界面中添加 IP 后缀(如 `.254`、进入建网`.253`、阿里阿帕`.252`),小站完成配置后重启网络服务。官网
验证 IP 绑定
使用 `ping` 命令测试每个 IP 地址是进入建网否生效。
```bash
ping 192.168.1.254
ping 192.168.1.253
ping 192.168.1.252
```
若能成功 ping 通,阿里阿帕说明配置正确。小站
二、官网配置虚拟主机
创建网站根目录
为每个 IP 地址创建独立的网站根目录,并写入主页文件。
```bash
mkdir -p /home/wwwroot/254
mkdir -p /home/wwwroot/253
mkdir -p /home/wwwroot/252
echo "IP: 192.168.1.254" > /home/wwwroot/254/index.html
echo "IP: 192.168.1.253" > /home/wwwroot/253/index.html
echo "IP: 192.168.1.252" > /home/wwwroot/252/index.html
```
配置 Apache(httpd.conf)
编辑主配置文件,为每个 IP 地址配置虚拟主机。示例如下:
```apache
ServerAdmin webmaster@254 DocumentRoot /home/wwwroot/254 ServerName www.254.example.com ErrorLog ${ APACHE_LOG_DIR}/error.log CustomLog ${ APACHE_LOG_DIR}/access.log combined
ServerAdmin webmaster@253 DocumentRoot /home/wwwroot/253 ServerName www.253.example.com ErrorLog ${ APACHE_LOG_DIR}/error.log CustomLog ${ APACHE_LOG_DIR}/access.log combined
ServerAdmin webmaster@252 DocumentRoot /home/wwwroot/252 ServerName www.252.example.com ErrorLog ${ APACHE_LOG_DIR}/error.log CustomLog ${ APACHE_LOG_DIR}/access.log combined
```
`ServerName` 可设置为域名或 IP 地址(如 `www.254.example.com`);
确保 `DocumentRoot` 指向对应的网站根目录。
启用虚拟主机并重启 Apache
保存配置文件后,重启 Apache 服务使配置生效。
```bash
systemctl restart apache2
```
或者使用旧版本命令:
```bash
service apache2 restart
```
三、测试网站
通过 IP 地址访问
在浏览器中输入 `http://192.168.1.254`,应显示对应 IP 的主页内容。
通过域名访问(可选)
配置 DNS 记录,将域名指向服务器 IP 地址,使用 `http://www.254.example.com` 访问。
注意事项
防火墙配置: 确保服务器防火墙允许 HTTP(80)和 HTTPS(443)流量; 权限设置