在 Apache 的 000-default 中只允许 localhost
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1250055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
To allow only localhost in Apache's 000-default
提问by Léo Léopold Hertz ??
How can you allow only localhost in Apache2?
你怎么能在Apache2中只允许本地主机?
My /etc/apache2/sites-enabled/000-default is
我的 /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>
I browse to http://localhost/index.phpunsuccessfully. I get Forbidden.
我浏览到http://localhost/index.php不成功。我明白了Forbidden。
回答by Jason Machacek
Switch your allow, deny order around (you want to deny all first, then allow localhost).
切换你的允许、拒绝顺序(你想先拒绝所有,然后允许本地主机)。
Change:
改变:
Order allow,deny
To:
到:
Order deny,allow
(which is the default behavior)
(这是默认行为)
回答by rafa
More simple. Look at the "/usr/shre/doc" configuration :) copy & paste!
更简单。查看“/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>
回答by Léo Léopold Hertz ??
Reply to Maha's answer
回复 Maha 的回答
This is the file which works for me. You can have what you want in the place of /var/www.
这是对我有用的文件。你可以在 /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>

