不支持的Apache2子站点的虚拟主机? [英] Does Apache2 support virtual hosting of subdomains?
问题描述
目前我的Apache服务器设置像这样
Currently my Apache server is set up like so
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www
</VirtualHost>
问题是,一切都低于 /无功/网络
是从其他地方访问。如果我有一个网页 /var/www/john/bio.html
,那么该网页可以从无功/网络借贷脚本/图片/简/
The problem is that everything below /var/www
is accessible from everywhere else. If I have a web page /var/www/john/bio.html
, then that web page could borrow scripts/pictures from var/www/jane/
我想设置我的Apache服务器像这样
I want to set up my Apache server like so
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www
</VirtualHost>
<VirtualHost *:80>
ServerName www.john.example.com
ServerAlias john.example.com
DocumentRoot /var/www/john
</VirtualHost>
<VirtualHost *:80>
ServerName www.jane.example.com
ServerAlias jane.example.com
DocumentRoot /var/www/jane
</VirtualHost>
因此,所有用户文件约翰
走在 /无功/网络/ JOHN /
文件夹,同样用户简
。然后,用符号链接关闭(默认)和访问只能从提供的/ var / WWW /用户/
向下(再次默认情况下),我没有担心约翰
网页包括脚本/图片简氏
网页。
So all the files for user john
go in the /var/www/john/
folder, and likewise for user jane
. Then, with symbolic links turned off (by default), and access only provided from /var/www/user/
downwards (again by default), I don't have to worry about john's
web page including scripts/images from jane's
web page.
推荐答案
只使用本地措施( / etc / hosts中
而不是DNS)我发现,这的确可以的工作。
Using local measures only (/etc/hosts
instead of a DNS) I found that this can indeed work.
首先,改变你的 / etc / hosts中
文件具有您所需的网站名称(S)的映射(的 www.example.com ),和目标IP地址(192.168.1.1)。我用我的本地IP地址。
First, change your /etc/hosts
file to have a mapping of your desired website name(s) (www.example.com), and target IP address (192.168.1.1). I used my local IP address.
IPAddress Hostname Alias
----------- -------------------------- ------------------
192.168.1.1 www.example.com example.com
192.168.1.1 www.john.example.com john.example.com
192.168.1.1 www.jane.example.com jane.example.com
您的网页浏览器会检查你的 / etc / hosts中
文件的之前看万维网。
Your web browser will check your /etc/hosts
file before looking at the world wide web.
接下来经过的所有Apache配置文件(的httpd.conf
, apache2.conf
, ports.conf
, conf.d / *
),并确保在一个文件的命令了NameVirtualHost *:80
发出(它没有被端口 80
但如果是多次发出,你会得到这个问题)。煤矿在 /etc/apache2/ports.conf
发出,所以把你那里,如果你不得不这样做。最后,更新您的Apache配置文件(我的是在的/ etc / apache2的/网站的可用/默认
),像这样。
Next go through all your Apache config files (httpd.conf
, apache2.conf
, ports.conf
, conf.d/*
) and make sure in exactly one file the command NameVirtualHost *:80
is issued (it doesn't have to be port :80
but if it is issued more than once, you will get this problem). Mine was issued in /etc/apache2/ports.conf
, so put yours there if you have to. Finally, update your Apache configuration file (mine was at /etc/apache2/sites-available/default
) like so.
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www
</VirtualHost>
<VirtualHost *:80>
ServerName www.john.example.com
ServerAlias john.example.com
DocumentRoot /var/www/john
</VirtualHost>
<VirtualHost *:80>
ServerName www.jane.example.com
ServerAlias jane.example.com
DocumentRoot /var/www/jane
</VirtualHost>
作为最后一步,你可能需要通过发出以下命令(这一步是没有必要的,如果你给所有的网站进入站点可用/默认$ c以添加网站到Apache $ C>和不进各个网站单独的文件)。
As a final step, you may need to add the websites to Apache by issuing the below commands (this step is not necessary, if you give all websites into sites-available/default
and not into separate files for individual websites).
# a2ensite www.example.com
# a2ensite www.john.example.com
# a2ensite www.jane.example.com
这样做了以后, john.example.com
将前往 /无功/网络/约翰·
。然后,该目录将作为根目录,约翰
将不再有机会获得 WWW
,,因此,有 /无功/网络/简
。
After doing this, john.example.com
will go to /var/www/john
. That directory will then act as the root directory, and john
will no longer have access to www
, and, therefore, have no access to /var/www/jane
.
同样,这样做后, jane.example.com
将前往 /无功/网络/简
。然后,该目录将作为根目录,简
将不再有机会获得 WWW
,,因此,都进不去 /无功/网络/约翰·
。
Likewise, after doing this, jane.example.com
will go to /var/www/jane
. That directory will then act as the root directory, and jane
will no longer have access to www
, and, therefore, have no access to /var/www/john
.
使用符号链接关闭 - 截至default--没有目录就可以互相访问
With symbolic links turned off --by default-- neither directories will be able to access each other
这篇关于不支持的Apache2子站点的虚拟主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!