Centos7/Centos8单独安装Httpd(附配置文件)

本文详细介绍了在CentOS7或CentOS8上安装Httpd服务的步骤,包括登录服务器、安装服务、启动与设置开机启动、调整网站目录权限、配置防火墙开放80端口,并解析了配置文件的位置和作用,如httpd.conf和日志管理。此外,还提醒了高版本Httpd配置时需要注意指定执行文件目录。
摘要由CSDN通过智能技术生成

1、登录阿里云服务器

2、安装httpd服务

执行指令:

yum -y install httpd

3、启动apache服务器

 systemctl start httpd
关闭apache服务器
 systemctl stop httpd

4、设置开机自动启动

 systemctl enable httpd

5、检查httpd服务状态

 systemctl status httpd.service

6、设置网站目录权限

根据你的目录情况更改,系统默认为/var/www/html

chmod -R 755 /var/www/html

如果是自己的目录要加用户
chown -R apache:apache /var/www/html

7、设置防火墙

防火墙阻挡了80端口,将80端口放开就行
添加

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --add-service=http
firewall-cmd --permanent --add-service=http           #写入配置文件

此时,httpd这个服务添加到了/etc/firewalld/zones/public.xml这个zone配置文件中,所以firewalld才能够据此放行。此文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="dhcpv6-client"/>
  <service name="http"/>
  <service name="ssh"/>
  <service name="https"/>
</zone>

重新载入

firewall-cmd --reload

查看

firewall-cmd --zone=public --query-port=80/tcp

安装目录介绍
Apache默认将网站的根目录指向/var/www/html 目录
默认的主配置文件是/etc/httpd/conf/httpd.conf
配置存储在的/etc/httpd/conf.d/目录

修改日志类型为按日期分类

注意

高版本的httpd必须要指定执行文件目录,否则会报错,也就是要加上
/usr/sbin/rotatelogs

ErrorLog  "|/usr/sbin/rotatelogs /var/log/httpd/error_log-%Y%m%d 86400 480"
CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/acc_log%Y%m%d 86400 480" combined

配置文件

httpd.conf

#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see 
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
# for a discussion of each configuration directive.
#
# See the httpd.conf(5) man page for more information on this configuration,
# and httpd.service(8) on using and configuring the httpd service.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so 'log/acc
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值