Centos7环境下的Apache配置与应用

1.安装Apache,使用yum系统完成
yum install httpd

2.Apache服务的启动/重启/关闭
在修改配置的完成,需要对此service先关闭,再启动,也可以选择重启操作。命令如下:

systemctl stop httpd.service #停止
systemctl start httpd.service #启动
systemctl restart httpd.service #重启

systemctl enable httpd.service #开机启动

3.对httpd.conf文件的修改,参数如下
a) 设定网站的默认访问端口80
b) 网站的根目录为/var/www/html
c) 默认的首页文件为default.html

文件地址/etc/httpd/conf/httpd.conf

4.配置修改并完成,重启服务,检查系统是否开始监听端口80
netstat -anp | grep 80
或者
lsof -i | grep 80
如果已经开始监听80端口,但仍然无法访问,则继续完成步骤5.

5.设置防火墙,设置端口80规则,允许端口访问。
Centos7默认使用firewall作为防火墙,所以要先改为iptables防火墙:
1>systemctl stop firewalld #先关闭firewall
2 >systemctl mask firewalld #直接暴力禁止掉firewall
3 >systemctl disable firewalld.service #禁止firewall开机启动
4>yum install iptables-services #安装iptables
5>在/etc/sysconfig/目录下找到iptables文件 或者iptables.rpmnew文件

编辑操作:vi /etc/sysconfig/iptables
添加规则:-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启iptables,并使规则生效:service iptables restart

6.在网站根目录下,使用echo命令新建default.html文件,页面内容是“Hello world”
cd /var/www/html
echo Hello world >default.html

7.验证和测试你的apache服务器,用ip打开访问。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值