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 配置相关文章

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