一、修改hosts文件(如果是服务器,该步不用)
不管你是否拥有上述域名,如果想通过域名访问自己建立的站点,这需要先对host文件进行修改。打开C:\Windows\System32\Drivers\etc目录下的 hosts 文件,增加一行:
- 127.0.0.1 www.shop1.com
具体文件如下:
- # Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
- 127.0.0.1 www.shop1.com
- 二、搜索 “Virtual hosts”
- # Virtual hosts
- # Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
- # Virtual hosts
- Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
- 在以上httpd-vhosts.conf里添加Virtual Host的配置
- # localhost
- <VirtualHost *:80>
- ServerName localhost
- DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
- <Directory "/Applications/XAMPP/xamppfiles/htdocs">
- Options Indexes FollowSymLinks Includes execCGI
- AllowOverride All
- Require all granted
- </Directory>
- </VirtualHost>
- # My custom host
- <VirtualHost *:80>
- ServerName mysite.local
- DocumentRoot "/Users/yourusername/path/to/your/site"
- <Directory "/Users/yourusername/path/to/your/site">
- Options Indexes FollowSymLinks Includes ExecCGI
- AllowOverride All
- Require all granted
- </Directory>
- ErrorLog "logs/mysite.local-error_log"
- </VirtualHost>
重启Apache,访问dev-domainname.com出现403错误,在httpd.conf里面搜索User Deamon,把deamon改成OS的用户名,重启Apache,就可以了。