我想在与Mac OS X 10.6捆绑在一起的本机Apache Web服务器上安装phpMyAdmin.我打开了系统偏好设置中的网络共享.然而,我担心的是我的计算机正在授予网络上每个人的访问权限.
> Mac中的Web共享/ Apache Web服务器的用户访问限制在哪里?
>如何限制除我自己以外的所有计算机的访问权限,以便我可以在localhost网络服务器上运行应用程序(如phpMyAdmin).
解决方法:
正如已经指出的那样,除非您专门将路由器中的http流量转发到您的计算机,否则您本地托管的内容只能供您和本地网络上的其他计算机使用.
回答有关限制只对您的计算机访问您的网络服务器的问题.你可以通过几种方式做到这一点.
请记住,无论何时更改apache配置,都需要重新启动apache才能使这些更改生效.
方法1
如果要将本地Web服务器上的所有内容限制为仅限本地计算机,请编辑文件“/etc/apache2/httpd.conf”.在大约195行,您将找到一个类似于以下内容的配置块:
<Directory "/Library/WebServer/Documents">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks MultiViews
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
您将要注释掉该块的底部两行并添加新规则
Deny from all
和
Allow from 127.0.0.1
该块现在应该是这样的:
<Directory "/Library/WebServer/Documents">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks MultiViews
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
#Order allow,deny
#Allow from all
Deny from all
Allow from 127.0.0.1
</Directory>
方法2
您还可以使用.htaccess文件来限制谁有权访问目录.要使.htaccess文件正常工作,首先需要启用它们.打开我在方法1(/etc/apache2/httpd.conf)中引用的相同文件,然后转到我之前提到的相同配置块(大约195行).你需要改变(大约215行):
AllowOverride None
至
AllowOverride All
完成后,您可以使用以下信息在Web服务器上的任何文件夹中创建名为.htaccess的文件:
Deny from all
Allow from 127.0.0.1
这将阻止除本地计算机之外的任何人访问该文件夹或其任何子文件夹的内容.
结论
方法1的好处是不必担心意外删除.htaccess文件或担心多个配置.方法2使得仅限制对Web服务器的某些目录的访问变得非常简单.
另请注意.htaccess文件必须包含文件名开头的那段时间(它是.htaccess而不是htaccess),当你要查看本地网络服务器时,你必须转到http://localhost(你不能使用) [你的电脑名称] .local).