Apache 配置域名

hosts 配置

# 主機ip        域名
127.0.0.1       www.casphp.com
127.0.0.1       www.gohosts.com

apache對應安裝目錄,打開httpd.conf

啓用apache的虛擬主機功能(去掉前面註釋#):

LoadModule vhost_alias_module modules/mod_vhost_alias.so

從httpd-vhosts.conf / vhosts.conf 導入虛擬主機配置:

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

Include conf/vhosts.conf  # window 平臺,apache 默認,

增加虛擬主機配置

<VirtualHost _default_:80>  # 默認訪問
DocumentRoot "F:\phpStud\PHPTutorial\WWW"
  <Directory "F:\phpStud\PHPTutorial\WWW">
    Options -Indexes -FollowSymLinks +ExecCGI  #Indexes:服務器可生成此目錄的文件列表。
    AllowOverride All  #
    Order allow,deny
    Allow from all
    Require all granted
  </Directory>
</VirtualHost>


<VirtualHost *:80>
    DocumentRoot "F:\phpStud\PHPTutorial\WWW\CasPHP\public" #網站訪問根目錄
    ServerName casphp.com  # 域名
    ServerAlias gohosts.com  #二階域名 
  <Directory "F:\phpStud\PHPTutorial\WWW\CasPHP\public">   #網站訪問根目錄
      Options FollowSymLinks ExecCGI   #FollowSymLinks:服務器可使用符號鏈接指向的文件或目錄。  ExecCGI:允許在此目錄中執行CGI程序。 
      AllowOverride All   #會根據設定的值決定是否讀取目錄中的.htaccess文件,來改變原來所設置的權限,All:讀取.htaccess文件的內容,修改原來的訪問權限。None:不讀取.
      AccessFileName ".htaccess" #指令用於指定保護目錄設定文件的文件名稱,默認值爲“.htaccess”。
      Order allow,deny  # Order用於指定allow和deny的先後次序。 allow 設定允許訪問Apache服務器的主機,Deny 設定拒絕訪問Apache服務器的主機
      Allow from all  #允許所有主機的訪問 
      # Allow from 202.96.0.97 202.96.0.98  允許來自指定IP地址主機的訪問
     Require all granted #Require 設定主機訪問
  </Directory>
</VirtualHost>

 配置文件修改後,重啓apache

Directory 配置相關文章

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章