Apache PHP 的一些设置

可能会遇到:在虚拟主机(VPS)上运行的Apache服务器不能重启。

一、设置禁止Apache显示目录索引

当用户访问目录时,Apache检测目录下是否有index.*、default.*等文件,有的话返回这些文件。没有的话会根据显示目录或者返回错误信息。具体如下图所示。
目录索引

  • 方法一:可以在根目录新建或修改 .htaccess 文件,在其中添加下面代码。此方法不用重启Apache。
<Files *>
     Options -Indexes
</Files>
  • 方法二:修改Apache配置文件”httpd.conf“(C:\AppServ\Apache2\conf
    • 找到http.conf相关部分,修改相关内容Options -Indexes FollowSymLinks MultiViews ExecCGI,主要是在“Indexes”前面添加“-”。此方法需要重启Apache服务器。
<Directory "C:/AppServ/www">

#
# 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.0/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks MultiViews ExecCGI

#
# 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>

[参考] http://www.jb51.net/article/46767.htm

二、WinServer 2008下,允许Apache通过防火墙

默认情况下,Apache服务会被Windows防火墙拦截。
1. 控制面板 | 系统与安全 | Windows防火墙 | 允许程序通过防火墙
2. 更改设置(如果不能进行下一步的话)
3. 允许运行另一个程序
允许程序通过防火墙
4. 添加程序 | 浏览
5. 选择Apache.exe

使用AppServ软件的话,默认路径为C:\AppServ\Apache2\bin\Apache.exe

三、开启所有php程序的输出缓存

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www ... .php on line 36

否则,可能会遇到上面问题。
1. 打开php.ini文件(C:\Windows\php.ini),设置output_buffering = On
php.ini
2. 重启Apache。(遇到不能重启Apache的,重启Windows)

[参考] http://blog.sina.com.cn/s/blog_6d4bfb040100muw3.html

四、打开、关闭PHP调试


  • 打开php.ini文件(C:\Windows\php.ini
  • 打开PHP调试,设置:display_errors = On
  • 关闭PHP调试,设置:display_errors = Off
  • 重启Apache。(遇到不能重启Apache的,重启Windows)

[参考] http://www.cnblogs.com/chenwenbiao/archive/2012/05/04/2482470.html

五、禁止访问某种扩展名的文件

在根目录的“.htaccess”文件(没有则新建)中添加如下内容:

<FilesMatch .(?i:gif|jpe?g|png)$> 
    Order allow,deny 
    Deny from all 
</FilesMatch> 

[参考] http://www.oschina.net/question/2002398_175340,链接中其他禁止设置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值