基于IP地址访问web服务器

基于IP访问web网站,当前网络的根目录为/www,创建当前网站虚拟目录,内容自定

第一步:配置网络,添加两个IP,192.168.198.10/24和192.168.198.11/24
[root@catyuan ~]# nmcli connection modify ens33 +ipv4.addresses 192.168.198.10/24 ipv4.gateway 192.168.198.1 ipv4.dns 114.114.114.114 ipv4.method manual connection.autoconnect yes
[root@catyuan ~]# nmcli connection modify ens33 +ipv4.addresses 192.168.198.11/24 ipv4.gateway 192.168.198.1 ipv4.dns 114.114.114.114 ipv4.method manual connection.autoconnect yes
[root@catyuan ~]# nmcli connection up ens33

第二步:创建网站存放目录,IP为192.168.198.10的文件存放在/www/10/,192.168.198.11的文件存放在/www/10下
[root@catyuan ~]# mkdir /www/{10,11} -pv
mkdir: created directory ‘/www’
mkdir: created directory ‘/www/10’
mkdir: created directory ‘/www/11’

第三步:编辑配置文件
[root@catyuan ~]# vim /etc/httpd/conf.d/vhosts.cof
<Directory "/www">
    AllowOverride None    ##允许覆盖
    # Allow open access: 
    Require all granted   ##设置目录访问权限
</Directory>

<VirtualHost 192.168.198.0:80>  IP地址
    DocumentRoot "/www/10"       ##指定当前主机访问网站
	ServerName 192.168.198.10     ##指定网站访问名称
    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"  ##错误日志
    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common  ##访问日志
</VirtualHost>

<VirtualHost 192.168.198.11:80>
    DocumentRoot "/www/11"
	ServerName 192.168.198.11
    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost>

第四步:网站内写入内容
[root@catyuan ~]# echo this is 192.168.198.10 > /www/10/index.html
[root@catyuan ~]# echo this is 192.168.198.11 > /www/11/index.html

第五步:重启服务并测试
[root@catyuan ~]# systemctl restart httpd

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是在 CentOS 8 上配置基于域名访问web 服务器的步骤: 1. 安装 Apache 在终端中输入以下命令安装 Apache: ``` sudo dnf install httpd ``` 2. 启动 Apache 安装完成后,输入以下命令启动 Apache: ``` sudo systemctl start httpd ``` 3. 设置开机自启 为了确保每次开机都能自动启动 Apache,输入以下命令: ``` sudo systemctl enable httpd ``` 4. 配置防火墙 如果您的 CentOS 8 上开启了防火墙,需要开启 HTTP 和 HTTPS 服务,输入以下命令: ``` sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload ``` 5. 配置虚拟主机 在 Apache 的配置文件中添加虚拟主机配置。在终端中输入以下命令编辑 Apache 主配置文件: ``` sudo vi /etc/httpd/conf/httpd.conf ``` 在文件末尾添加以下内容: ```apache <VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined </VirtualHost> ``` 其中,`example.com` 和 `www.example.com` 分别是您的域名和子域名,`/var/www/example.com` 是您网站的根目录。 6. 创建网站目录 在终端中输入以下命令创建网站根目录: ``` sudo mkdir /var/www/example.com ``` 7. 创建网页 在 `/var/www/example.com` 目录下创建一个名为 `index.html` 的文件,输入以下命令: ``` sudo vi /var/www/example.com/index.html ``` 在文件中输入以下内容: ```html <!DOCTYPE html> <html> <head> <title>My Website</title> </head> <body> <h1>Welcome to My Website</h1> <p>This is my first web page.</p> </body> </html> ``` 保存并退出文件。 8. 重启 Apache 在完成上述步骤后,需要重启 Apache 使配置生效,输入以下命令: ``` sudo systemctl restart httpd ``` 9. 修改 hosts 文件 在客户端电脑的 hosts 文件中添加以下内容: ``` your_server_ip example.com your_server_ip www.example.com ``` 将 `your_server_ip` 替换为您的服务器 IP 地址。 10. 访问网页 在浏览器中输入您的域名或子域名,您应该能够看到您创建的网页。 希望这些步骤能够帮助您在 CentOS 8 上配置基于域名访问web 服务器

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值