如何在Apache 2中只允许本地主机?
- 我的/etc/apache 2/已启用站点/000-默认为 *
<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
。
4条答案
按热度按时间ubof19bj1#
切换allow、deny的顺序(您希望先拒绝所有,然后再允许localhost)。
变更:
收件人:
(这是默认行为)
jc3wubiy2#
更简单。看看“/usr/shre/doc”的配置:)复制和粘贴!
busg9geu3#
回复摩诃的回答
这是适合我的文件。你可以在/var/www的地方找到你想要的。
tcbh2hod4#
如果要配置多个虚拟主机,其中一些允许从本地主机外部访问,而另一些不允许,则在遵循此页面上其他答案中的修复后,原始问题中的方法将有效。
但是,如果希望只允许localhost,则在顶层配置中更改
Listen
和ServerName
即可。因此,可能会在系统防火墙中阻塞该端口。