因为博客备份到本地,每次修改数据库改网址好麻烦,就想在本地也用域名访问。
因为我用wampserver,需要开启虚拟主机,过程如下:
1、打开http.conf文件
2、搜索vhosts
,第一个是
- # Virtual hosts
- #Include conf/extra/httpd-vhosts.conf
将include前面的#号去掉就可以了。
3、继续搜索vhosts
,第二个是
- IncludeOptional "E:/WAMP/vhosts/*"
请将这个前面的#号去掉,要不访问会出现403。
4、然后是虚拟主机配置,放置在安装目录的vhosts里,名字就取“域名.conf”
配置示例如下:
- localhost.conf
- <VirtualHost *:80>
- ServerAdmin no-reply@localhost.com
- DocumentRoot "E:/WAMP/www"
- ServerName localhost
- ServerAlias localhost
- ErrorLog "logs/localhost-error.log"
- CustomLog "logs/localhost-access.log" common
- </VirtualHost>
- www.chaiwubi.com
- <VirtualHost *:80>
- ServerAdmin no-reply@chaiwubi.com
- DocumentRoot "E:/WAMP/www/CMS/chaiwubi"
- ServerName chaiwubi.com
- ServerAlias www.chaiwubi.com
- ErrorLog "logs/chaiwubi.com-error.log"
- CustomLog "logs/chaiwubi.com-access.log" common
- </VirtualHost>
<Directory "D:/phpweb/test/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
<Directory "D:/phpweb/test2/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
<Directory "D:/phpweb/jzcms/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>