1.Apache的安装及启用
前提:ip和软件仓库设置好
(1)安装
dnf install httpd.x86_64 -y
(2)启用
systemctl enable --now httpd //开启服务并设定服务位开机启动
firewall-cmd --list-all //查看火墙信息
firewall-cmd --permanent --add-service=http //在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https //在火墙中永久开启https访问
firewall-cmd --reload
2.Apache基本配置
(1)端口修改
vim /etc/httpd/conf/httpd.conf
编辑内容
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
systemctl restart httpd
浏览器输入ip
浏览器输入 ip:8080
(2)默认发布文件
vim /etc/httpd/conf/httpd.conf
编辑内容
vim /var/www/html/westos.html
编辑内容
systemctl restart httpd
浏览器输入ip
3.Apache的虚拟主机
(1)实验准备
mkdir -p /var/www/virtual/westos.org/{linux,news}
echo linux > /var/www/virtual/westos.org/linux/index.html
echo news > /var/www/virtual/westos.org/news/index.html
echo 123 > /var/www/html/index.html
(2)实验步骤
vim /etc/httpd/conf.d/vhosts.conf
编辑内容
systemctl restart httpd
vim /etc/hosts
编辑内容
测试:firefox分别输入www.westos.org linux.westos.org news.westos.org
www.westos.org
linux.westos.org
news.westos.org
4.Apache语言支持
(1)php
vim /var/www/html/index.php
编辑内容
dnf install php -y
systemctl restart httpd
测试 http://192.168.0.11/index.php
(2)cgi
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
编辑内容
vim /etc/httpd/conf/httpd.conf
编辑内容
systemctl restart httpd
chmod +x /var/www/html/cgi/index.cgi
semanage fcontext -l | grep cgi //搜索安全上下文
chcon -Rt httpd_sys_script_exec_t /var/www/html/cgi/ //更改目录及其内部文件的安全上下文
restorecon -RvvF /var/www/html/cgi/
5.Apache的加密访问
dnf install mod_ssl -y
openssl req --newkey rsa:2048 -nodes -sha256 -keyout /etc/httpd/westos.org.key -x509 -days 365 -out /etc/httpd/westos.org.crt
cd /etc/httpd/
ls
vim /etc/httpd/conf.d/ssl.conf
编辑内容
systemctl restart httpd
测试 https://192.168.155.100
6.Apache自带前缀https://
vim /etc/httpd/conf.d/vhosts.conf
编辑内容
systemctl restart httpd
vim /etc/hosts
编辑内容
测试: 输入login.westos.org