centos配置web服务器

centos web服务器:apache或者naginx都比较好,下面是用apache

输入yum install -y httpd来进行web服务器服务的下载(nat)

systemctl start httpd # 启动httpd服务

systemctl status httpd # 查看httpd服务

查看此时防火墙的状态,如果防火墙是开启的状态就有可能导致web服务器无法使用,即没法客户机没法用浏览器来访问web服务器

systemctl status firewalld.service

(active(running))如果显示这个就说明防火墙处于激活状态,所以我们得关闭防火墙

systemctl stop firewalld.service #执行停止运行防火墙命令

systemctl status firewalld.service

如果在active显示dead就说明防火墙服务关闭成功

systemctl disable firewalld.service #禁止防火墙自启动
systemctl start firewalld.service #开启防火墙
systemctl enable firewalld.service #防火墙随系统开启启动
防火墙有关的命令

查看centos的IP地址

用浏览器访问

配置apache:httpd的默认配置文件为:/etc/httpd/conf/httpd.conf 由三部分组成;

在/var/www/html/新建一个index.html并进行编辑;浏览器测试;

基于域名的多站点配置

编写/etc/httpd/conf.d/domain1.conf

<VirtualHost 192.168.28.132:80>
ServerName www.domain1.com
DocumentRoot "/var/www/domain1/html"
customlog "logs/domain1.log" combined
</VirtualHost>
<directory /var/www/domain1/html>
require all granted
</directory>

在/var/www/domain1/html/index.html写上测试网页

编写/etc/httpd/conf.d/domain2.conf

<VirtualHost 192.168.28.132:80>
ServerName www.domain2.com
DocumentRoot "/var/www/domain2/html"
customlog "logs/domain2.log" combined
</VirtualHost>
<directory /var/www/domain2/html>
require all granted
</directory>

在/var/www/domain2/html/index.html写上测试网页

然后就是vim /etc/hosts

修改完配置文件后重启apache使配置文件生效

systemctl restart httpd

打开虚拟机的浏览器依次输入www.domain1.comwww.domain2.com

基于ip的多站点配置

添加临时ip

[root@localhost www]# ifconfig ens33:1 192.168.135.158 netmask 255.255.255.0 up

[root@localhost www]# ifconfig ens33:2 192.168.135.159 netmask 255.255.255.0 up

编写/etc/httpd/conf.d/ip1.conf

<VirtualHost 192.168.135.158:80>
DocumentRoot "/var/www/ip1/html"
customlog "logs/ip1.log" combined
</VirtualHost>
<directory /var/www/ip1/html>
require all granted
</directory>

在/var/www/ip1/html/index.html写上测试网页

编写/etc/httpd/conf.d/ip2.conf

<VirtualHost 192.168.135.159:80>
DocumentRoot "/var/www/ip2/html"
customlog "logs/ip2.log" combined
</VirtualHost>
<directory /var/www/ip2/html>
require all granted
</directory>

在/var/www/ip2/html/index.html写上测试网页

重启Apache使配置文件生效 systemctl restart httpd

分别访问192.168.135.158 和 192.168.135.159 (这两个ip是我们加上的临时ip)

基于端口的多站点配置

我们使用8080和8081端口作为网站的端口

编写/etc/httpd/conf.d/port1.conf

Listen 8080
<VirtualHost 192.168.28.132:8080>
DocumentRoot "/var/www/port1/html"
customlog "logs/port1.log" combined
</VirtualHost>
<directory /var/www/port1/html>
require all granted
</directory>

在/var/www/port1/html/index.html写上测试网页

编写/etc/httpd/conf.d/port2.conf

Listen 8081
<VirtualHost 192.168.28.132:8081>
DocumentRoot "/var/www/port2/html"
CustomLog "logs/port2.log" combined
</VirtualHost>
<Directory /var/www/port2/html>
Require all granted
</Directory>

在/var/www/port2/html/index.html写上测试网页

在我们监听端口的过程中,由于centos8中的Selinux机制,可能操作系统不让我们监听一些特定的端口,我们需要把他关掉

setenforce 0  #临时关闭,重启恢复

重启

systemctl restart httpd

分别访问http://192.168.135.157:8080/http://192.168.135.157:8081/

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

麻瓜 Moffat Nvata

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值