apache服务器安装部署
yum install httpd -y ###安装apache服务软件
yum install httpd=manual -y ###apache手册
systemctl start httpd
systemctl enable httpd
firewall-cmd --permanent --add-service=http ###永久允许http
firewall-cmd --reload ###防火墙重新加载策略
apache基本信息
/var/www/html ###apache的默认发布目录
/var/www/html/index ###apache的默认发布文件
/etc/httpd/conf/httpd.conf ###apache主配置文件
/etc/httpd/conf.d/*.conf ###apache子配置文件
netstat -antlupe | grep httpd ###查看apache默认端口,80端口
httpd_sys_content_t ###默认安全上下文
/etc/httpd/logs/* ###apache日志
测试:编辑发布文件index.html,打开浏览器,输入apache服务器IP
cd /var/www/html/
vim index.html
<h1>test.page<h1>
<h2>hello world!<h2>
修改默认端口
vim /etc/httpd/conf/httpd.conf
###80端口无法访问
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
###访问自定义端口
当selinux状态为0,警告模式时,修改端口后服务无法启动,当selinux状态为enforcing,强制模式时,服务可以启动,但是不能访问指定端口
firewall-cmd --permanent --add-port=6666/tcp
firewall-cmd --reload
semanage port -a -t http_port_t -p tcp 6666
semamage port -l | grep http ###查看端口
###修改完成后就可以访问6666端口
修改默认发布文件
cd /var/www/html
vim westos.html
修改配置文件
vim /etc/httpd/conf/httpd.conf
重启服务
注:上面两个发布文件谁在前面优先读取谁,如果前面的不存在了,则读取后面的
修改默认发布目录
cd /var/www/html
mkdir /westos/web/html -p ###新建指定的发布目录
vim /westos/web/html/westos.html
vim /etc/httpd/conf/httpd.conf
重启服务,当我们访问浏览器时,不能查看默认发布文件,这是因为selinux对文件安全上下文的影响,我们指定的目录与原默认发布目录安全上下文标签不一致,因此我们需要修改指定发布目录安全上下文
semanage fcontext -a -t htypd_sys_content_t '/westos/(/.*)?'
restorecon -RvvF /westos/
重启服务再次访问就可以了
当配置文件修改完重启服务失败时,在/etc/httpd/log/erro_log
查看报错信息