如何只允许Apache2中的localhost?
我的/ etc / apache2 / sites-enabled / 000-default是
<VirtualHost *:80>
ServerAdmin webmaster@localhost
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
。
答案 0 :(得分:18)
切换你的允许,拒绝订单(你想先拒绝所有,然后允许localhost)。
变化:
Order allow,deny
要:
Order deny,allow
(这是默认行为)
答案 1 :(得分:7)
更简单。看看&#34; / usr / shre / doc&#34;配置:) copy&amp;粘贴!
<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>
答案 2 :(得分:1)
回复Maha的回答
这是适合我的文件。你可以在/ var / www。
的位置拥有你想要的东西<VirtualHost *:80>
ServerAdmin webmaster@localhost
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>