httpd基於域名不一樣的虛擬主機配置

apache2.2.x版本php

1. 註釋主配置文件/etc/httpd/conf/httpd.conf中的 DoucumentRoothtml

#DocumentRoot "/var/www/html"

 

2.把主配置文件NameVirtualHost前面註釋去掉,添加本地主機名稱apache

NameVirtualHost 192.168.136.131:80

 

3.若是註釋了ServerName,或者默認爲localahost:80或者127.0.0.1:80則會報錯,但不影響虛擬主機的使用dom

"Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
                                                           [  OK  ]

4.在主配置文件下面添加虛擬主機的配置文件ide

<VirtualHost 192.168.136.131:80>   //本地主機名稱 ,這個基於用戶認證登陸
  DocumentRoot /var/www/virtual/test1  //網站根目錄 
  ServerName www.test1.com           //域名1
  ErrorLog logs/error_logs               //錯誤日誌地址
  CustomLog  logs/custom_logs combined //常規日誌,combined類型記錄
 <Directory /var/www/virtual/test1/>  //配置網站目錄權限

Options None
#AllowOverRide None                    
 AllowOverride AuthConfig                //添加基用戶認證登陸配置
 AuthType Basic
 AuthName "test"                                
 AuthUserFile "/etc/httpd/conf/htpasswd"  //認證用戶密碼存放位置
 Require user test                                  //只容許test登陸
 Order allow,deny                                    //容許全部用戶訪問
 allow from all
 </Directory>
</VirtualHost>

<VirtualHost 192.168.136.131:80>          //常規配置
  ServerAdmin sean@test.com                //域名2  
  DocumentRoot /var/www/virtual/test2/
  ServerName www.test2.com
  ErrorLog logs/error_logs
</VirtualHost>

 

而後重啓httpd網站

 

httpd2.4.x版本ui

 1.主配置文件只須要把VirtualHost下面Incalude一行去掉註釋便可spa

# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf

2.配置/etc/httpd/extra/httpd-vhost.conf日誌

 

 

<VirtualHost *:80>    //這裏不要填寫127.0.0.1或者localhost,能夠用 「*「 或者本機的 內網IP外網IP 
    ServerAdmin admin@test.com       
    DocumentRoot "/usr/local/apache/htdocs/www.a.org"
    ServerName "www.a.org"
    DirectoryIndex index.html index.php
    ErrorLog "logs/www.a.org-error_log"
    CustomLog "logs/www.a.org-access_log" combined
</VirtualHost>

<VirtualHost *:80>

    ServerAdmin admin@test.com
    DocumentRoot "/usr/local/apache/htdocs/www.b.org"
    ServerName "www.b.org"
    DirectoryIndex index.html index.php
    ErrorLog "logs/www.b.org-error_log"
    CustomLog "logs/www.b.org-access_log" combined
</VirtualHost>

3.重啓服務code

相關文章
相關標籤/搜索