【问题标题】:To allow only localhost in Apache's 000-default在 Apache 的 000-default 中只允许 localhost
【发布时间】:2009-08-08 22:35:00
【问题描述】:

如何在 Apache2 中只允许本地主机?

我的 /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

【问题讨论】:

  • 这个问题更适合serverfault.com
  • 请将此问题移至serverfault解决问题。

标签: apache


【解决方案1】:

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

变化:

Order allow,deny

收件人:

Order deny,allow

(这是默认行为)

【讨论】:

  • 这是正确的。但是,在我的情况下(使用 macos x Mountain Lion)我还必须允许 ipv6 localhost 地址,即我添加了以下附加行:Allow from fe80::1
  • 从 Apache 2.4 开始,您现在可以改写 Require local
【解决方案2】:

更简单。查看“/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>

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多