Apache部署
1.关于Apache
#apache的基本信息/etc/httpd/conf #apache的配置目录/etc/http/conf.d #子配置目录/etc/httpd/conf/httpd.conf #主配置文件/lib/systemd/system/htpd.service #启动文件:80 #默认端口/var/www/html #默认发布目录index.html #默认发布文件
2.Apache安装
#安装apache
dnf install httpd -y
#在火墙中放行web服务
firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https
#开启服务
systemctl enable --now httpd
#生成默认测试页文件并进行测试
echo 172.25.254.128 > /var/www/html/index.html
curl 172.25.254.128
3.Apache的基本配置信息
#修改配置文件
vim /etc/httpd/conf/httpd.conf
#刷新服务
systemctl reload httpd
#设定火墙通过
firewall-cmd --permanent --add-port=8080/tcp
重启防火墙:
firewall-cmd --reload
#检测
curl 172.25.254.128:8080
在ip为172.25.254.128的机器上测试:
在ip为172.25.254.30的机器上测试:
4.修改默认发布目录
#建立默认发布目录
mkdir /web/html -p
#修改配置文件
vim /etc/httpd/conf/httpd.conf
重启服务:
systemctl restart httpd
为进行测试,对新的html文件填入内容:
echo "/web/html!" > /web/html/index.html
进行测试:
#建立新的默认发布文件
echo "rin!!!" > /web/html/rin.html
#当没有对配置进行修改时新默认发布文件不会被默认访问,测试结果访问的还是index.html
只有指定访问时才能访问到rin.html文件
#修改配置文件
vim /etc/httpd/conf/httpd.conf
#重启服务
systemctl reload httpd
#测试:
curl 172.25.254.128:8080
5.https
#安装mod_ssl
dnf install mod_ssl -y
#建立证书和key文件目录
mkdir /etc/httpd/certs
openssl req \
> -newkey rsa:2048 \
> -nodes \
> -sha256 \
> -keyout /etc/httpd/certs/rin.org.key \
> -x509 \
> -days 365 \
> -out /etc/httpd/certs/rin.org.crt
输入后会出现以下文字提示框,含义如下表所示:
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:shanxi
Locality Name (eg, city) [Default City]:xian
Organization Name (eg, company) [Default Company Ltd]:rin
Organizational Unit Name (eg, section) []:webserver
Common Name (eg, your name or your server's hostname) []:www.rin.org
Email Address []:rin@rin.org
字段 | 含义说明 | 你的配置值 |
---|---|---|
Country Name (2 letter code) | 国家代码(2 个字母) | CN(中国) |
State or Province Name | 省 / 自治区名称(全称) | shanxi(山西省) |
Locality Name | 城市名称 | xian(西安市,注:正确拼音为 Xi'an) |
Organization Name | 组织 / 公司名称 | rin(你的组织名) |
Organizational Unit Name | 部门 / 单位名称 | webserver(Web 服务器部门) |
Common Name | 通用名称(通常是服务器域名或主机名) | www.rin.org(你的域名) |
Email Address | 联系邮箱 | rin@rin.org(你的邮箱) |
完成后能看到证书出现:
#编辑主配置文件
vim /etc/httpd/conf.d/ssl.conf
注意:原证书链接要注释掉:
#重启服务
systemctl reload httpd
netstat -antlupe | grep httpd
端口改为80:
#在浏览器中访问
https://服务器ip
6.apache的虚拟主机
#为每个发布站点建立默认发布目录
mkdir -p /var/www/virtual/rin.org/newsmkdir -p /var/www/virtual/rin.org/bbs
#为每个站点建立默认发布文件
echo new.rin.org > /var/www/virtual/rin.org/news/index.html
echo bbs.rin.org > /var/www/virtual/rin.org/bbs/index.html
#修改配置文件
vim /etc/httpd/conf.d/vhosts.conf
#刷新服务
systemctl reload httpd
#测试:
1.在浏览器所在主机中手动编写本地解析文件
vim /etc/hosts
2.测试效果