我有域名,我已经设置了虚拟主机我想知道如何将域名连接到我的虚拟主机我是新的,所以请回答容易理解的答案
http-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "C:/wamp/www">
Order Deny,Allow
Deny from all
Allow from localhost
</Directory>
</VirtualHost>
<VirtualHost example.com>
DocumentRoot "C:/wamp/www/example"
ServerName example.com
ServerAlias example.com
Options Indexes FollowSymLinks
<Directory C:/wamp/www>
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
我想使用域名内部和外部
来显示网站答案 0 :(得分:0)
好的,我们假设您的域名为mysite.com
,您还需要该网站的测试版本,比方说mysite.dev
您使用过Apache 2.2语法,因此我假设您使用的是2.2.x的Apache版本,但是如果您使用的是Apache 2.4.x,请参阅下面的语法正确
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
<Directory "C:/wamp/www">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from localhost
</Directory>
</VirtualHost>
# This is for accessing a development version of the site
# note: only accessible from this machine
<VirtualHost *:80> <-- change
DocumentRoot "C:/wamp/www/mysite.test"
ServerName mysite.dev
<Directory "C:/wamp/www/mysite.test">
Options Indexes FollowSymLinks <-- moved
Order Deny,Allow
Deny from all
Allow from localhost 127.0.0.1 ::1
</Directory>
</VirtualHost>
#New Virtual Host for your real domain name
#accessible from the internet
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mysite.com"
ServerName mysite.com
ServerAlias www.mysite.com
<Directory "C:/wamp/www/mysite.com">
Options Indexes FollowSymLinks
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
如果您使用的是Apache 2.4.x,那么语法应该是这样的: -
#NameVirtualHost *:80 <- not required in apache 2.4
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
<Directory "C:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
# This is for accessing a development version of the site
# note: only accessible from this machine and stored in different folder
<VirtualHost *:80> <-- change
DocumentRoot "C:/wamp/www/mysite.test"
ServerName example.dev
<Directory "C:/wamp/www/mysite.test">
Options Indexes FollowSymLinks <-- moved
Require local
</Directory>
</VirtualHost>
#New Virtual Host for your real domain name
#accessible from the internet
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mysite.com"
ServerName mysite.com
ServerAlias www.mysite.com
<Directory "C:/wamp/www/mysite.com">
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
您需要将mysite.dev
网站添加到Windows HOSTS文件c:\windows\system32\drivers\etc\hosts
,但不是实时域名
127.0.0.1 localhost
127.0.0.1 mysite.dev
::1 localhost
::1 mysite.dev