怎么在CentOS 8上安裝與配置Apache虛擬主機(jī),很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

| Apache服務(wù)器是現(xiàn)代操作系統(tǒng)包括UNIX和Windows等開發(fā)和維護(hù)開源的HTTP服務(wù)器,apache提供一個安全、高效、可擴(kuò)展的服務(wù)器,提供與當(dāng)前HTTP標(biāo)準(zhǔn)同步的HTTP服務(wù)。 |
實驗環(huán)境
操作系統(tǒng): Centos 8
web應(yīng)用:apache
內(nèi)網(wǎng)IP:192.168.3.21
shell執(zhí)行:root

以root或具有sudo權(quán)限的用戶身份登錄執(zhí)行如下操作。
安裝httpd服務(wù)
[root@linuxcool ~]# yum install httpd-devel.x86_64 httpd.x86_64 httpd-tools.x86_64
驗證httpd是否安裝成功
[root@linuxcool ~]# httpd -v Server version: Apache/2.4.6 (CentOS) Server built: Apr 2 2020 13:13:23
啟動httpd服務(wù)
[root@linuxcool ~]# systemctl start httpd.service [root@linuxcool ~]# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2020-05-22 12:23:03 CST; 25s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 952 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" Tasks: 6 Memory: 3.6M CGroup: /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 -DFOREGROUND May 22 12:23:03 linuxcool systemd[1]: Starting The Apache HTTP Server... May 22 12:23:03 linuxcool httpd[952]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, u...message May 22 12:23:03 linuxcool systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.
apache安裝成功,默認(rèn)web目錄/var/www/
測試
http://192.168.3.21/

安裝成功!
配置apache虛擬主機(jī)創(chuàng)建網(wǎng)站目錄
[root@linuxcool ~]# mkdir -p /var/www/web1 [root@linuxcool ~]# mkdir -p /var/www/web2
web1添加index.html
[root@linuxcool ~]# vim /var/www/web1/index.html <!DOCTYPE html> <html dir="ltr"> <head> <meta charset="utf-8"> <title>Welcome to Web1</title> </head> <body> <h2>Success! Web1 home page!</h2> </body> </html>
web2添加index.html
[root@linuxcool ~]# vim /var/www/web2/index.html <!DOCTYPE html> <html dir="ltr"> <head> <meta charset="utf-8"> <title>Welcome to Web1</title> </head> <body> <h2>Success! Web1 home page!</h2> </body> </html>
授權(quán)web目錄權(quán)限
[root@linuxcool ~]# chown -R apache: /var/www/web1/ [root@linuxcool ~]# chown -R apache: /var/www/web2/
創(chuàng)建虛擬主機(jī)文件
#web1
[root@linuxcool ~]# vim /etc/httpd/conf.d/web1.conf <VirtualHost *:80> ServerName web1.com ServerAlias www.web1.com ServerAdmin webmaster@example.com DocumentRoot /var/www/web1 <Directory /var/www/web1/> Options -Indexes +FollowSymLinks AllowOverride All </Directory> ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined </VirtualHost>
#web2
[root@linuxcool ~]# vim /etc/httpd/conf.d/web2.conf <VirtualHost *:80> ServerName web2.com ServerAlias www.web2.com ServerAdmin webmaster@example.com DocumentRoot /var/www/web2 <Directory /var/www/web2/> Options -Indexes +FollowSymLinks AllowOverride All </Directory> ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined </VirtualHost>
重啟httpd服務(wù)
[root@linuxcool ~]# systemctl restart httpd.service
驗證httpd虛擬主機(jī)結(jié)果
http://www.web1.com

http://www.web2.com

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。
網(wǎng)站名稱:怎么在CentOS8上安裝與配置Apache虛擬主機(jī)-創(chuàng)新互聯(lián)
本文鏈接:http://chinadenli.net/article10/edjdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、網(wǎng)站營銷、標(biāo)簽優(yōu)化、網(wǎng)站設(shè)計公司、網(wǎng)站內(nèi)鏈、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容