2009-08-08 43 views
12

如何只允许在Apache2中的本地主机?只允许Apache的本地主机的000-默认

/000默认我的/ etc/apache2的/启用的网站,是

<VirtualHost *:80> 
     ServerAdmin [email protected] 

DocumentRoot /home/masi/Dropbox/a 
<Directory /> 
       Options FollowSymLinks 
       AllowOverride None 
     </Directory> 
     <Directory /home/masi/Dropbox/a/> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride None 
       Order allow,deny 
       deny from all        // Problem HERE! 
     allow from 127.0.0.1 
     </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 /var/log/apache2/error.log 

     # Possible values include: debug, info, notice, warn, error, crit, 
     # alert, emerg. 
     LogLevel warn 

     CustomLog /var/log/apache2/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> 

我浏览到http://localhost/index.php失败。我得到Forbidden

+2

这个问题更适合http://serverfault.com。 – 2009-08-08 22:36:23

+0

请将此问题移至serverfault以解决问题。 – 2009-08-08 22:45:51

回答

17

切换你的允许,拒绝顺序(你想先拒绝,然后允许本地主机)。

变化:

Order allow,deny 

要:

Order deny,allow 

(这是默认行为)

+0

谢谢你的回答!它解决了这个问题。 – 2009-08-08 23:01:55

+2

这是正确的。但是,在我的情况下(使用macos x Mountain Lion),我还必须允许ipv6 localhost地址,那就是我添加了以下附加行:允许来自fe80 :: 1 – Alexander 2013-10-21 01:23:47

+0

从Apache 2.4开始,现在只需编写[需要本地'](https://httpd.apache.org/docs/current/mod/mod_authz_host.html) – 2016-08-19 11:02:35

1

回复摩诃的回答

这是适用于文件我。你可以在/ var/www的地方找到你想要的。

<VirtualHost *:80> 
     ServerAdmin [email protected] 

     DocumentRoot /var/www 
     <Directory /> 
       Options FollowSymLinks 
       AllowOverride None 
     </Directory> 
     <Directory /var/www/> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride None 
       Order deny,allow 
       deny from all 
     allow from 127.0.0.1 
     </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 /var/log/apache2/error.log 

     # Possible values include: debug, info, notice, warn, error, crit, 
     # alert, emerg. 
     LogLevel warn 

     CustomLog /var/log/apache2/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> 
5

更简单。看看“/ usr/shre/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> 
相关问题