本文介绍了限制通过IP地址访问的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Apache网络服务器,说ip是 12.345.678.90 。在我的www目录也有一些网站,说,站点1 站点2 。两者属于相同的IP地址 - 我创建的虚拟主机。网站上CakePHP的框架,里面有很多的目录,例如,应用应用程序的/ tmp LIB 的lib /蛋糕等访问像 http://site1.com 或 http://site2.com 万事大吉了,没办法,这些目录中可以查看或访问,而是通过IP我所看到的一切。

I have a webserver with apache, say ip is 12.345.678.90. In my www directory there are a few sites, say, site1 and site2. Both belong to the same ip address - I created virtual hosts. Websites are on cakephp framework and there are a lots of directories, for example, app, app/tmp, lib, lib/Cake etc. When accessing the website like http://site1.com or http://site2.com everything is all right, and no way these directories can be viewed or accessed, but through ip I can see everything.

http://12.345.678.90/
http://12.345.678.90/site1/lib
http://12.345.678.90/site1/app
http://12.345.678.90/site1/app/tmp

等 - 所有这些目录中包含了每个站点的文件是可见的。所以,我怎么能prevent任何一种通过IP地址访问的?其实开场仅仅在IP http://12.345.678.90 它只是显示没事的时候,因为我创造了空 index.html的文件,但我不能做到这一点对所有的文件夹,(或创建htaccess的每个目录)。这可以通过一个htaccess的,或者更好的处理,由Apache的配置,或者通过一些其他的方式?

etc - all this directories with containing files for each site are visible. So, how I can prevent any kind of access through ip address ? Actually when opening just the ip http://12.345.678.90 it just shows nothing, as I had created empty index.html file, but I cant do that for all the folders,(or create htaccess for each directory). Can this be handled through single htaccess, or maybe better, by apache config, or by some other way ?

感谢

推荐答案

试试这个

要禁用目录列表

在Apache配置文件(httpd.conf文件)文件中找到的目录部分,例如:的/ var / www / html等

In your Apache configuration file (httpd.conf) file locate the directory section eg: /var/www/html

<Directory "/var/www/html">
   Options Indexes FollowSymLinks
   AllowOverride None
   Order allow,deny
   Allow from all
</Directory>

删除单词索引或更改索引 -Indexes

然后重新启动Apache服务器服务的httpd重新启动

Then restart your Apache server service httpd restart

限制访问:一级目录

您可以通过添加限制访问某些目录下面的

You can restrict access to certain directories by adding the following

<Directory "/var/www/html/site1/mydirectory">
   Order allow,deny
   Deny from all
</Directory>

通过增加上述配置到Apache的conf文件中的 mydirectory 将被阻塞/从访问受限制的。

By adding the above configuration to apache conf file the mydirectory will be blocked/restricted from access.

限制访问:文件级

。添加 -

<Directory "/var/www/html/site1/mydirectory">
  Order allow,deny
  Allow from all
    <Files myfile.php>
        Order allow,deny
    </Files>
</Directory>

的所有文件通过IP地址prevent访问

 <Files ~ ".+">
  Order allow,deny
  Deny from all
</Files>

这篇关于限制通过IP地址访问的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 13:33