CentOS搭建Apache服务器

安装对应的软件包

root@hds \~# yum install httpd mod_ssl -y

查看防火墙的状态和selinux

root@hds \~# systemctl status firewalld

root@hds \~# cat /etc/selinux/config

若未关闭,则关闭防火墙和selinux

root@hds \~# systemctl stop firewalld

root@hds \~# systemctl disable firewalld

Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.

Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

root@hds \~# setenforce 0

root@hds \~# sed "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

启动httpd服务设为开机自启

root@hds \~# systemctl start httpd

root@hds \~# systemctl enable httpd

Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

创建三个网站根目录对应三种用户

root@hds \~# mkdir /www/8080 -p

root@hds /# mkdir /www/80

root@hds /# mkdir /www/ssl

配置根目录网站文件

root@hds 80# echo "welcome to 80" > skills80.html

root@hds 8080# echo "welcome to 8080" > skills8080.html

root@hds ssl# echo "welcome to ssl" > skillsssl.html

创建并配置网站:8080的访问控制文件和网站访问用户

root@hds 8080# vim .htaccess

authname "welcome to 8080"

#访问目录时的提示信息

authtype basic

#加密类型

authuserfile /www/8080

#存储访问网站用户的账号密码信息

require valid-user

#允许密码文件中的用户访问
root@hds 8080# htpasswd -cb .htpasswd webuser1 webuser1

Adding password for user webuser1

root@hds 8080# htpasswd -b .htpasswd webuser2 webuser2

Adding password for user webuser2

生成https的密钥和证书

cd /etc/pki/tls/private

root@hds private# openssl genrsa -out ca.key 2048

root@hds private# openssl req -x509 -new -key ca.key -out ca.crt -days 365

root@hds private# mv ca.crt ../certs/

修改证书和密钥的位置

root@hds \~# vim /etc/httpd/conf.d/ssl.conf

基于<VirtualHost default:443>该字段配置基于域名的虚拟主机

<VirtualHost default:443>

DocumentRoot "/www/ssl/"

ServerName www.hds.com

<Directory "/www/ssl/">

options all

AllowOverRide none

Require all granted

</Directory>

配置8080和80的网站

root@hds \~# vim /etc/httpd/conf/httpd.conf

Listen 80

<VirtualHost 192.168.126.166:80>

DocumentRoot "/www/80/"

ServerName www.hds.com

<Directory "/www/80/">

Options all

AllowOverRide none

Require all granted

</Directory>

</VirtualHost>

Listen 8080

<VirtualHost 192.168.126.166:8080>

DocumentRoot "/www/8080/"

ServerName www.hds.com

<Directory "/www/8080/">

Options all

AllowOverRide all

require all granted

</Directory>

</VirtualHost>

修改可以检索的网页文件

测试

8080端口

443端口

80端口

相关推荐
优化Henry31 分钟前
LTE 站点 S1 链路反复闪断导致小区频闪退服故障排查
运维·网络·学习·信息与通信·tdd
心之王者71638 分钟前
Linux 进程信号:从产生、阻塞到捕捉与子进程回收
linux·服务器·网络
AndreaYYmm1 小时前
日志里 grep 到 Fail 就判失败?这六个假阳性我全踩过
linux·shell
manageengine1 小时前
服务器 CPU 100% 怎么排查:8 条命令从现象定位到根因
运维·服务器·cpu
分布式存储与RustFS1 小时前
RustFS 分片上传怎么配:大文件断点续传的最小可验证流程
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
赤生云电竞1 小时前
云游戏边缘节点部署:机房选址与网络拓扑优化实践 —— 从80ms时延预算看节点落位与Spine-Leaf组网
服务器·游戏·spine
爱吃香菜的初学者2 小时前
二十五.Linux——epoll
linux·运维·服务器
少司府2 小时前
嵌入式外设篇(一)GPIO·一:认识GPIO
linux·单片机·嵌入式硬件·mcu·系统·rtos·嵌入式软件
宽海智能仓储物流3 小时前
宽海智能WCS系统常见问题全解析:从选型对接、运维定制到降本增效
运维·数据仓库·自动化
无奈笑天下4 小时前
银河麒麟上DHCP无法获取IP地址问题处理
linux·运维·服务器·网络协议