安装完apache 应做的20件事情

来源:互联网 发布:纳森网络 编辑:程序博客网 时间:2024/05/21 06:21

安装完apache 应做的20件事情
1,编辑apache的配置文件
[root@www ~]# vi /etc/httpd/conf/httpd.conf
2,ServerTokens OS  ← 找到这一行,将“OS”改为“Prod”(在
出现错误页的时候不显示服务器操作系统的名称)
 ↓
ServerTokens Prod   ← 变为此状态
3,ServerSignature On  ← 找到这一行,将“On”改为“Off”
 ↓
ServerSignature Off  ← 在错误页中不显示Apache的版本
4,ServerAdmin root@localhost  ← 将管理员邮箱设置为自己常用

的邮箱
 ↓
ServerAdmin zy66289214@126.com  ← 根据实际情况修改默认设置
5,#ServerName new.host.name:80  ← 修改主机名
 ↓
ServerName www.hello521.com:80  ← 根据实际情况修改,端口号

保持默认的80
6,Options Indexes FollowSymLinks  ← 找到这一行,删除

“Indexes”,并添加“Includes”、“ExecCGI”
 ↓
Options Includes ExecCGI FollowSymLinks  ← 允许服务器执行

CGI及SSI
7,#AddHandler cgi-script .cgi  ← 找到这一行,去掉行首的“#

”,并在行尾添加“.pl”
 ↓
AddHandler cgi-script .cgi .pl  ← 允许扩展名为.pl的CGI脚本

运行
8,AllowOverride None  ← 找到这一行,将“None”改为“All”
 ↓
AllowOverride All  ← 变为此状态,允许.htaccess
9,LogFormat "%h %l %u %t /"%r/" %>s %b /"%{Referer}i/" /"%

{User-Agent}i/"" combined  ← 找到这一行
 ↓
LogFormat "%h %l %u %t /"%!414r/" %>s %b /"%{Referer}i/"

/"%{User-Agent}i/"" combined  ← 改为此状态(添加“!414”到

规则中,对于过长的日志不记录)
10,AddDefaultCharset UTF-8  ← 找到这一行,在行首添加“#”
 ↓
#AddDefaultCharset UTF-8  ← 不使用UTF-8作为网页的默认编码
AddDefaultCharset GB2312  ← 并接着添加这一行(添加GB2312为

默认编码)
11,<Directory "/var/www/icons">  ← 找到这一个标签,并在标

签中更改相应选项
  Options Indexes MultiViews  ← 找到这一行,将“Indexes

”删除
    ↓
  Options MultiViews   ← 变为此状态(不在浏览器上显示树

状目录结构)
12,删除测试页
[root@www ~]# rm -rf /etc/httpd/conf.d/welcome.conf

/var/www/error/noindex.html
13,设置开机自启动
[root@www ~]# chkconfig --list httpd
httpd           0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关

闭  6:关闭
[root@www ~]# chkconfig httpd on
[root@www ~]# chkconfig --list httpd
httpd           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启

用  6:关闭
14,[root@www ~]# service httpd restart 从新启动httpd以更改

新的配置
15,建立测试页
[root@www ~]# vi /var/www/html/index.html
<html>
<head>
<meta http-equiv="Content-Type" c>
<title>Hello,World!</title>
<body>
Hello,欢迎加入linux 企业讨论群13275765
</body>
</html>
在客户端输入 http://192.168.1.11 请对应自己的服务器地址建议

使用火狐浏览器,如果不能正确显示中文请修改火狐浏览器的utf8
[root@www ~]# rm -rf /var/www/html/index.html 删除测试页
16.测试php
[root@www ~]# vi /var/www/html/test.php
<?php
phpinfo();
?>
在客户端输入 http://192.168.1.11/test.php 请对应自己的服务器

地址
17,测试cgi
[root@www ~]# vi /var/www/html/test.cgi
#!/usr/bin/perl
print "Content-Type: text/html/n/n";
print "<html><body>";
print "Hello,World!CGI is working!<br>";
print "</body></html>";
[root@www ~]# chmod 755 /var/www/html/test.cgi
在客户端输入 http://192.168.1.11/test.cgi 请对应自己的服务器

地址

18,对SSI进行测试

[root@www ~]# vi /var/www/html/test.shtml  ← 建立SSI测试页

,内容如下:

<html>
<head>
<meta http-equiv="Content-Type" c>
<title>Hello,World!</title>
<body>
TEST SSI
<!--#config timefmt="%Y/%m/%d %H:%M:%S" -->
<!--#echo var="DATE_LOCAL" -->
</body>
</html>
在客户端输入 http://192.168.1.11/shtml
19,5] 对.htaccess的支持进行测试

[root@sample ~]# vi /var/www/html/index.shtml  ← 建

立.htaccess测试用的页,内容如下:


<html>
<head>
<meta http-equiv="Content-Type" c>
<title>Hello,World!</title>
<body>
The name of the file is <!--#echo var="DOCUMENT_NAME" -->
</body>
</html>  

  然后在浏览器中输入“http://192.168.1.11,如果显示

“Forbidden”,说明.htaccess正常。

  然后建立一个.htaccess文件,并定义相应规则,如下:

[root@sample html]# vi /var/www/html/.htaccess  ← 建

立.htaccess文件,内容如下:

DirectoryIndex index.shtml
然后在浏览器中输入“http://192.168.1.11如果正确显示“ The

name of the file is index.shtml”,说明.htaccess中的规则生效

状态,OK。
20 删除测试用的文件
[root@www ~]# rm -f /var/www/html/* /var/www/html/.htaccess

转载:http://blog.163.com/herod_xiao/blog/static/8718839920097255429502/

原创粉丝点击