怎么在CentOS 8上安裝與配置Apache虛擬主機,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
成都創新互聯公司是專業的奉新網站建設公司,奉新接單;提供網站制作、成都網站建設,網頁設計,網站設計,建網站,PHP網站建設等專業做網站服務;采用PHP框架,可快速的進行奉新網站開發網頁制作和功能擴展;專業做搜索引擎喜愛的網站,專業的做網站團隊,希望更多企業前來合作!
Apache服務器是現代操作系統包括UNIX和Windows等開發和維護開源的HTTP服務器,apache提供一個安全、高效、可擴展的服務器,提供與當前HTTP標準同步的HTTP服務。 |
實驗環境
操作系統: Centos 8
web應用:apache
內網IP:192.168.3.21
shell執行:root
以root或具有sudo權限的用戶身份登錄執行如下操作。
安裝httpd服務
[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服務
[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安裝成功,默認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.htmlWelcome to Web1 Success! Web1 home page!
web2添加index.html
[root@linuxcool ~]# vim /var/www/web2/index.htmlWelcome to Web1 Success! Web1 home page!
授權web目錄權限
[root@linuxcool ~]# chown -R apache: /var/www/web1/ [root@linuxcool ~]# chown -R apache: /var/www/web2/
創建虛擬主機文件
#web1
[root@linuxcool ~]# vim /etc/httpd/conf.d/web1.confServerName web1.com ServerAlias www.web1.com ServerAdmin webmaster@example.com DocumentRoot /var/www/web1 Options -Indexes +FollowSymLinks AllowOverride All ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined
#web2
[root@linuxcool ~]# vim /etc/httpd/conf.d/web2.confServerName web2.com ServerAlias www.web2.com ServerAdmin webmaster@example.com DocumentRoot /var/www/web2 Options -Indexes +FollowSymLinks AllowOverride All ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined
重啟httpd服務
[root@linuxcool ~]# systemctl restart httpd.service
驗證httpd虛擬主機結果
http://www.web1.com
http://www.web2.com
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注創新互聯行業資訊頻道,感謝您對創新互聯的支持。