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![](https://i-blog.csdnimg.cn/direct/3adb1206f33e48468e6d9029fcda0c2e.png) ## **基于\该字段配置基于域名的虚拟主机** > \ > > DocumentRoot "/www/ssl/" > > ServerName www.hds.com > > \ > > options all > > AllowOverRide none > > Require all granted > > \ ## **配置8080和80的网站** > \[root@hds \~\]# vim /etc/httpd/conf/httpd.conf > > Listen 80 > > \ > > DocumentRoot "/www/80/" > > ServerName www.hds.com > > \ > > Options all > > AllowOverRide none > > Require all granted > > \ > > \ > > Listen 8080 > > \ > > DocumentRoot "/www/8080/" > > ServerName www.hds.com > > \ > > Options all > > AllowOverRide all > > require all granted > > \ > > \ ![](https://i-blog.csdnimg.cn/direct/6b8fea4d43bb45bd8a41bc455e8ad193.png) ## **修改可以检索的网页文件** ![](https://i-blog.csdnimg.cn/direct/6a8d44c30d0b4274a18fd7b961b5d487.png) ## **测试** 8080端口 ![](https://i-blog.csdnimg.cn/direct/f4a00d05db804c5285bd7003c4c29545.png) 443端口 ![](https://i-blog.csdnimg.cn/direct/b93bd0987fd6425baecb24f66361310a.png) 80端口 ![](https://i-blog.csdnimg.cn/direct/06a62301328d49a282bb7f8fc921261b.png)

相关推荐
一路随云000009 分钟前
基于Unity YooAsset自动化资源管理框架,附源代码
运维·自动化
数数科技的数据干货1 小时前
从爆款到厂牌:解读游戏工业化的业务持续增长道路
运维·数据库·人工智能
大聪明-PLUS4 小时前
如何使用 Docker 打包一个简单的应用程序:简易指南
linux·嵌入式·arm·smarc
深耕AI5 小时前
【完整教程】宝塔面板FTP配置与FileZilla连接服务器
运维·服务器
serve the people5 小时前
Prompts for Chat Models in LangChain
java·linux·langchain
李昊哲小课6 小时前
Ubuntu 24.04 MariaDB 完整安装与配置文档
linux·ubuntu·mariadb
无聊的小坏坏6 小时前
从单 Reactor 线程池到 OneThreadOneLoop:高性能网络模型的演进
服务器·网络·一个线程一个事件循环
AI智域边界 - Alvin Cho7 小时前
Bloomberg、LSEG 与 MCP 缺口:为什么尚未发布完整的 MCP 服务器,以及多智能体系统如何解決这问题
运维·服务器
人间打气筒(Ada)7 小时前
zerotier内网穿透部署(rockylinux部署本地服务器)超详细~~~
linux·内网穿透·内网·公网·zerotier·穿透
Elias不吃糖8 小时前
Git常用指令合集
linux·git