Apache PHP 的一些设置

来源:互联网 发布:网络管理的协议 编辑:程序博客网 时间:2024/05/17 02:01

可能会遇到:在虚拟主机(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
原创粉丝点击