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