代码之家  ›  专栏  ›  技术社区  ›  Léo Léopold Hertz 준영

仅允许Apache的000默认值中的localhost

  •  14
  • Léo Léopold Hertz 준영  · 技术社区  · 15 年前

    如何只允许Apache2中的localhost?

    my/etc/apache2/sites enabled/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 .

    3 回复  |  直到 10 年前
        1
  •  18
  •   Jason Machacek    15 年前

    切换您的允许,拒绝周围的顺序(您要先拒绝所有,然后允许本地主机)。

    变化:

    Order allow,deny
    

    到:

    Order deny,allow
    

    (默认行为)

        2
  •  6
  •   rafa    10 年前

    更简单。查看“/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
  •  1
  •   Léo Léopold Hertz 준영    15 年前

    回应玛哈的回答

    这是适合我的文件。你可以用你想要的来代替/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>