2009-08-08 6 views
12

Comment pouvez-vous autoriser uniquement localhost dans Apache2?Pour autoriser uniquement localhost dans la valeur 000 par défaut d'Apache

/etc/apache2/sites-enabled/000 par défaut est

<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> 

Je passe en revue à http://localhost/index.php sans succès. Je reçois Forbidden.

+2

Cette question convient mieux à http://serverfault.com. –

+0

Veuillez déplacer cette question vers serverfault pour résoudre le problème. –

Répondre

17

Changez votre autorisation, refusez l'ordre (vous voulez tout d'abord refuser, puis autoriser localhost).

Change:

Order allow,deny 

Pour:

Order deny,allow 

(ce qui est le comportement par défaut)

+0

Merci pour votre réponse! Cela résout le problème. –

+2

Ceci est correct. Cependant, dans mon cas (en utilisant macos x Mountain Lion) j'ai aussi dû autoriser l'adresse ipv6 localhost, c'est-à-dire que j'ai ajouté la ligne additonnelle suivante: Allow from fe80 :: 1 – Alexander

+0

A partir d'Apache 2.4, vous pouvez maintenant écrire [' Exiger local'] (https://httpd.apache.org/docs/current/mod/mod_authz_host.html) à la place –

1

Répondre à la réponse de Maha

Ceci est le fichier qui fonctionne pour moi. Vous pouvez avoir ce que vous voulez à la place de/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

Plus simple. Regardez la configuration "/ usr/shre/doc" :) copier & coller!

<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> 
Questions connexes