
虚拟主机的配置&https配置
安装并配置Apache,与APR和APR-Util。 配置三个虚拟主机,设置不同的DocumentRoot和ServerName。 启用mod_ssl,生成HTTPS证书。 确保所有配置正确无误,启动服务并测试访问。
发布日期:2021-05-15 14:04:06
浏览次数:23
分类:精选文章
本文共 3858 字,大约阅读时间需要 12 分钟。
三种虚拟主机的配置
一、配置之前的操作
安装Apache服务器
在开始配置之前,首先需要安装Apache服务器。以下是安装步骤:
[root@localhost ~]# yum -y install gcc gcc-c++ wget make pcre-devel openssl openssl-devel libtool expat-devel[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
解压安装包
[root@localhost ~]# wget https://mirrors.bfsu.edu.cn/apache/httpd/httpd-2.4.46.tar.gz[root@localhost ~]# wget https://mirrors.bfsu.edu.cn/apache/apr/apr-1.7.0.tar.gz[root@localhost ~]# wget https://mirrors.bfsu.edu.cn/apache/apr/apr-util-1.6.1.tar.gz[root@localhost ~]# tar xf httpd-2.4.46.tar.gz[root@localhost ~]# tar xf apr-1.7.0.tar.gz[root@localhost ~]# tar xf apr-util-1.6.1.tar.gz
编辑配置文件
[root@localhost apr-1.7.0]# cd apr-1.7.0[root@localhost-14.7.0]# vim configure
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install
[root@localhost apr-util-1.6.1]# cd /usr/src/apr-util-1.6.1[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --withapr=/usr/local/apr[root@localhost apr-util-1.6.1]# make && make install
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork[root@localhost httpd-2.4.46]# make && make install
启动Apache
[root@localhost httpd-2.4.46]# /usr/local/apache/bin/apachectl start
其他配置
[root@localhost httpd-2.4.46]# cd /etc/httpd24[root@localhost httpd-2.4.46]# vim httpd.conf
[root@localhost httpd-2.4.46]# vim /etc/profile.d/httpd.sh[root@localhost httpd-2.4.46]# source /etc/profile.d/httpd.sh
修改IP地址
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
[root@localhost ~]# systemctl restart NetworkManager[root@localhost network-scripts]# ifdown ens33; ifup ens33
二、相同IP不同端口
[root@localhost httpd-2.4.46]# vim /etc/httpd24/httpd.conf
[root@localhost httpd-2.4.46]# vim extra/httpd-vhosts.conf
创建文件夹并移动源码
[root@localhost htdocs]# mkdir yh1 yh2[root@localhost htdocs]# cd CSS3卡通猫咪动画代码[root@localhost CSS3卡通猫咪动画代码]# mv * ../yh1[root@localhost CSS3卡通猫咪动画代码]# cd ..[root@localhost htdocs]# cd HTML5圣诞老人过悬崖小游戏[root@localhost HTML5圣诞老人过悬崖小游戏]# mv * ../yh2[root@localhost htdocs]# cd yh1[root@localhost yh1]# lscss index.html
对吗?嗯,我可能需要额外的步骤来确保HTTPS配置正确。让我检查一下之前的步骤是否正确完成了。
等等,我似乎少了生成证书和HTTPS配置的步骤。这对于配置HTTPS非常重要。我需要回顾一下之前的步骤,看看是否需要添加或者修改任何部分。
好的,现在我将重点放在生成证书和HTTPS配置上。
生成证书
[root@localhost opt]# cd /etc/pki/CA[root@localhost CA]# umask 077[root@localhost CA]# openssl genrsa -out private/cakey.pem 2048[root@localhost CA]# mkdir private[root@localhost CA]# umask 077[root@localhost CA]# openssl genrsa -out private/cakey.pem 2048
[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365
[root@localhost CA]# mkdir certs newcerts crl[root@localhost CA]# touch index.txt[root@localhost CA]# echo 01 > serial
客户端生成证书请求
[root@localhost opt]# umask 077[root@localhost opt]# openssl genrsa -out httpd.key 2048[root@localhost opt]# openssl req -new -key httpd.key -days 365 -out httpd.csr
CA签署证书
[root@localhost opt]# openssl ca -in httpd.csr -out httpd.crt -days 365[root@localhost opt]# mv httpd.crt httpd.key /etc/httpd24/[root@localhost opt]# cd[root@localhost ~]# cd /etc/httpd24[root@localhost httpd24]# lsextra httpd.conf httpd.crt httpd.key[root@localhost httpd24]# apachectl restart
检查端口是否正确
[root@localhost httpd24]# ss -antl
这看起来有什么问题吗?哦,对了,我需要确保mod_ssl已经正确加载,并且配置文件中引用的证书路径正确。
可能还有查看日志的步骤,确保Apache没有报错信息。
嗯,感觉还差一点,但至少看起来配置是正确的。完成后,我应该可以通过浏览器访问这些虚拟主机,确保HTTPS也正常工作。
总结一下,我需要完成以下步骤:
好的,现在我可以开始编写正式的虚拟主机配置步骤了。
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2025年05月13日 17时37分38秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Mac OS下错误The superclass “javax.servlet.http.HttpServlet“ was not found on the Java Build Path的解决方法
2025-04-11
Mac os如何安装绿盾客户端
2025-04-11
mac xmind 激活
2025-04-11
Mac 下 Python+Selenium 自动上传西瓜视频
2025-04-11
mac 下 react Native ios环境搭建
2025-04-11
Mac 下使用sourcetree操作git教程
2025-04-11
mac 下如何建立vue-cli项目
2025-04-11
mac 安装PIL
2025-04-11
Mac 开发PhoneGap 应用,怎样加入插件 barcodescaner
2025-04-11
mac 搭建APK反编译环境[转]
2025-04-11
MAC 显示隐藏文件
2025-04-11
Mac 的“任务管理器” —— 活动监视器
2025-04-11
mac 配置环境变量,讲的太仔细了,非常棒
2025-04-11
mac-gradle的安装和配置
2025-04-11
mac/ip/TCP/udp报文格式与理论大小
2025-04-11
Mac:Permission denied XXX
2025-04-11
macaca 测试web(2)
2025-04-11