这篇文章主要介绍了Centos8中如何部署Apache虚拟机的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Centos8中如何部署Apache虚拟机文章都会有所收获,下面我们一起来看看吧。

实验环境

操作系统:Centos 8

web应用:apache

内网IP:192.168.3.21

shell执行:root

以root或具有sudo权限的用户身份登录执行如下操作。

安装httpd服务

[root@linuxcool~]#yuminstallhttpd-devel.x86_64httpd.x86_64httpd-tools.x86_64验证httpd是否安装成功

[root@linuxcool~]#httpd-vServerversion:Apache/2.4.6(CentOS)Serverbuilt:Apr2202013:13:23

启动httpd服务

[root@linuxcool~]#systemctlstarthttpd.service[root@linuxcool~]#systemctlstatushttpd.service●httpd.service-TheApacheHTTPServerLoaded:loaded(/usr/lib/systemd/system/httpd.service;disabled;vendorpreset:disabled)Active:active(running)sinceFri2020-05-2212:23:03CST;25sagoDocs:man:httpd(8)man:apachectl(8)MainPID:952(httpd)Status:"Totalrequests:0;Currentrequests/sec:0;Currenttraffic:0B/sec"Tasks:6Memory:3.6MCGroup:/system.slice/httpd.service├─952/usr/sbin/httpd-DFOREGROUND├─953/usr/sbin/httpd-DFOREGROUND├─954/usr/sbin/httpd-DFOREGROUND├─955/usr/sbin/httpd-DFOREGROUND├─956/usr/sbin/httpd-DFOREGROUND└─957/usr/sbin/httpd-DFOREGROUNDMay2212:23:03linuxcoolsystemd[1]:StartingTheApacheHTTPServer...May2212:23:03linuxcoolhttpd[952]:AH00558:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,u...messageMay2212:23:03linuxcoolsystemd[1]:StartedTheApacheHTTPServer.Hint:Somelineswereellipsized,use-ltoshowinfull.

apache安装成功,默认web目录/var/www/

测试

http://192.168.3.21/

安装成功!

配置apache虚拟主机

创建网站目录

[root@linuxcool~]#mkdir-p/var/www/web1[root@linuxcool~]#mkdir-p/var/www/web2

web1添加index.html

[root@linuxcool~]#vim/var/www/web1/index.htmlnbsp;html>"ltr">"utf-8">WelcometoWeb1Success!Web1homepage!

web2添加index.html

[root@linuxcool~]#vim/var/www/web2/index.htmlnbsp;html>"ltr">"utf-8">WelcometoWeb2Success!Web2homepage!

授权web目录权限

[root@linuxcool~]#chown-Rapache:/var/www/web1/[root@linuxcool~]#chown-Rapache:/var/www/web2/

创建虚拟主机文件

#web1

[root@linuxcool~]#vim/etc/httpd/conf.d/web1.confServerNameweb1.comServerAliaswww.web1.comServerAdminwebmaster@example.comDocumentRoot/var/www/web1Options-Indexes+FollowSymLinksAllowOverrideAllErrorLog/var/log/httpd/example.com-error.logCustomLog/var/log/httpd/example.com-access.logcombined

#web2

[root@linuxcool~]#vim/etc/httpd/conf.d/web2.confServerNameweb2.comServerAliaswww.web2.comServerAdminwebmaster@example.comDocumentRoot/var/www/web2Options-Indexes+FollowSymLinksAllowOverrideAllErrorLog/var/log/httpd/example.com-error.logCustomLog/var/log/httpd/example.com-access.logcombined

重启httpd服务

[root@linuxcool~]#systemctlrestarthttpd.service

验证httpd虚拟主机结果

http://www.web1.com

http://www.web2.com

关于“Centos8中如何部署Apache虚拟机”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Centos8中如何部署Apache虚拟机”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。