我在运行ubuntu 12.04的服务器中设置了一个网页。
我已经停用了默认网站(a2dissite默认default-ssl),我创建了一个新的网站,我需要一个工作的网站。
想象一下,我有foo.com。 我的目标是foo.com抛出403 http错误,sub.foo.com渲染我需要的网页。 我的虚拟主机看起来像这样:
foo.com(默认)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName foo.com
DocumentRoot /var/www/default
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/default/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
sub.foo.com
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName sub.foo.com
DocumentRoot /var/www/sub
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/sub/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
当我访问sub.foo.com时,会显示该页面。 当我访问foo.com时,会显示相同的页面(:S),我需要403 ...
我做错了什么?
答案 0 :(得分:0)
您是否在Apache配置中启用了NamedVirtualHosts? Apache重启时会给你任何警告吗?是否启用了所有网站?
他们配置了不同的DocumentRoots,所以我猜你在两个路径中都有相同的文件,或者实际上是由同一个vhost配置提供的两个请求。
在 foo.com 的配置中,我首先将Allow from all
更改为Deny from all
:
<Directory /var/www/default/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Deny from all
</Directory>
......你有更大的机会与403一起受到这种变化的欢迎;)