2015-11-17 17:03:49
来 源
itjs.cn
Linux Apache配置
此文详细介绍apache和mod_jk方法,希望对于初学Apache服务器相关的朋友有帮助,更多Apache安装、配置、报错处理等资源请本站内搜索。

(0)源码安装

shell> tar xzvf httpd-2.2.10.tar.gz

shell> cd httpd-2.2.10

如果要装suexec支持cgi的sudo,则:

shell> ./configure --prefix=/usr/local/apache2 --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache2/cgi-bin

如果是媒体服务器的用户media,需要以下:

shell> ./configure --prefix=/usr/local/apache2 --enable-suexec --with-suexec-caller=media --with-suexec-docroot=/usr/local/apache2/cgi-bin

否则一般情况下:

shell> ./configure --prefix=/usr/local/apache2 --enable-module=so --enable-module=rewrite --enable-ssl=static --with-ssl=/usr/local/ssl //(ssl开启https)

#这里我们通过enable-module参数告诉设置脚本,我们需要启动so和 rewrite模块,so模块是用来提DSO支持的apache核心模块,而rewrite模块则是用意实现地址重写的模块,由于rewrite模块需要 DBM支持,如果在初次安装时没有编译进apache,以后需要用到时需要重新编译整个apache才可以实现。为此除非你可以确定以后不会用到 rewrite模块,否则还是建议你在第一次编译的时候把rewrite模块编译好。

shell> make

shell> make install

shell> vi /etc/rc.local , 写入:

### added by abiao

/usr/local/apache2/bin/apachectl start

### abiao end

shell> /usr/local/apache2/bin/apachectl start

如果碰到:httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

则修改httpd.conf的#ServerName www.example.com:80 为:

ServerName 192.168.10.253:80

设置开机自启动

cd /usr/local/apache2/bin/

cp apachectl /etc/rc.d/init.d/httpd

chmod 700 /etc/rc.d/init.d/httpd

vi /etc/rc.d/init.d/httpd

在 # |||||||||||||||||||| START CONFIGURATION SECTION |||||||||||||||||||下面添加下面三行|

#Comments to support chkconfig on RedHat Linux

#chkconfig: 2345 90 90

#description:http server

注意:前面的# 不能少,没有这三行,在使用chkconfig 时会提示你:service httpd does not support chkconfig

============================================================================

(01)mod_jk安装

拷贝 mod_jk-1.2.26-httpd-2.2.6.so 到 /usr/local/apache2/modules

编辑httpd.conf , 添加如下行:

LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.6.so

JkWorkersFile conf/workers.properties

JkMountFile conf/uriworkermap.properties

JkLogFile logs/mod_jk.log

JkShmFile logs/jk-runtime-status

JkLogLevel warn

<Location /jkstatus>

Order Deny,Allow

Deny from all

# abiao's pc

Allow from 192.168.12.17

</Location>

在conf目录下创建workers.properties文件,添加:

# list the workers by name

worker.list=status, boss241, boss242, boss29, boss35, boss240, boss195, boss159, boss142

worker.status.type=status

# server 1

# ------------------------

worker.boss241.port=8009

worker.boss241.host=192.168.18.241

worker.boss241.type=ajp13

# server 2

# ------------------------

worker.boss242.port=8009

worker.boss242.host=192.168.18.242

worker.boss242.type=ajp13

# server 3

# ------------------------

worker.boss29.port=8009

worker.boss29.host=192.168.18.29

worker.boss29.type=ajp13

# server 4

# ------------------------

worker.boss35.port=8009

worker.boss35.host=192.168.18.35

worker.boss35.type=ajp13

# server 5

# ------------------------

worker.boss240.port=8009

worker.boss240.host=192.168.18.240

worker.boss240.type=ajp13

# server 6

# ------------------------

worker.boss195.port=8009

worker.boss195.host=192.168.18.195

worker.boss195.type=ajp13

# server 7

# ------------------------

worker.boss159.port=8009

worker.boss159.host=192.168.43.159

worker.boss159.type=ajp13

# server 8

# ------------------------

worker.boss142.port=8009

worker.boss142.host=192.168.45.142

worker.boss142.type=ajp13

在conf目录下创建uriworkermap.properties文件,添加:

#/*=bossbalancer

/jkstatus=status

/td/*.jsp=boss240

/td/*.action=boss240

/td/dwr/*.*=boss240

/td/userfiles/*.*=boss240

/td/fckeditor/*.*=boss240

/de/*.*=boss87

/koyoo/*=boss159

/mt2/*=boss35

/WebServiceConf/*=boss159

/pe/*.jsp=boss241

/pe/*.action=boss241

/pe/dwr/*.*=boss241

/pe/userfiles/*.*=boss241

/pe/fckeditor/*.*=boss241

/pl/*.jsp=boss241

/pl/*.action=boss241

/pl/dwr/*.*=boss241

/pl/userfiles/*.*=boss241

/pl/fckeditor/*.*=boss241

/ip/*.jsp=boss241

/ip/*.action=boss241

/ip/dwr/*.*=boss241

/ip/userfiles/*.*=boss241

/ip/fckeditor/*.*=boss241

/boss/*=boss240

/nc/*.jsp=boss242

/nc/*.action=boss242

/nc/dwr/*.*=boss242

/nc/userfiles/*.*=boss242

/nc/fckeditor/*.*=boss242

/co/*.jsp=boss242

/co/*.action=boss242

/co/dwr/*.*=boss242

/co/userfiles/*.*=boss242

/co/fckeditor/*.*=boss242

/fi/*.jsp=boss242

/fi/*.action=boss242

/fi/dwr/*.*=boss242

/fi/userfiles/*.*=boss242

/fi/fckeditor/*.*=boss242

/bottom-service/*.jsp=boss29

/bottom-service/*.action=boss29

/bottom-service/dwr/*.*=boss29

/bottom-service/userfiles/*.*=boss29

/bottom-service/fckeditor/*.*=boss29

/address-book/*.*=boss29

/attendance/*.*=boss29

/pip/*.*=boss240

/hr/*.*=boss195

/pg/*.*=boss195

/doc2/*.*=boss195

/am/*.*=boss29

===============================================================================

(02) apache 支持中文URL路径浏览

复制 mod_encoding.so 和 mod_headers.so 文件到/usr/local/apache2/modules/目录下

shell> cd /root/abiao-disk

shell> tar -xzvf mod_encoding-20021209.tar.gz

shell> cd mod_encoding-20021209/lib

shell> ./configure

shell> make

shell> make install

shell> vi /usr/local/apache2/conf/httpd.conf

加入:

LoadModule headers_module modules/mod_headers.so

<IfModule mod_headers.c>

Header add MS-Author-Via "DAV"

</IfModule>

LoadModule encoding_module modules/mod_encoding.so

<IfModule mod_encoding.c>

EncodingEngine on

NormalizeUsername on

SetServerEncoding GBK

DefaultClientEncoding UTF-8 GBK GB2312

AddClientEncoding "(Microsoft .* DAV $)" UTF-8 GBK GB2312

AddClientEncoding "Microsoft .* DAV" UTF-8 GBK GB2312

AddClientEncoding "Microsoft-WebDAV*" UTF-8 GBK GB2312

</IfModule>

shell> /usr/local/apache2/bin/apachectl restart

=================================================================================

(2) 查看apache版本

# cd /usr/local/apache2/bin

./httpd -v

(3) 一旦服务器编译完成,就可以用以下命令列出所有已经被编译到服务器中的模块,包括MPM。

./httpd -l

如果启动apache 报错:

[[email protected] lib]# /usr/local/apache2/bin/apachectl restart

httpd: Syntax error on line 61 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/mod_encoding.so into server: libiconv_hook.so.1: cannot open shared object file: No such file or directory

就要:

shell> vi /etc/ld.so.conf

加入:

/usr/local/lib

shell> ldconfig //让路径起作用

如果启动apache 报错:

[[email protected] httpd]# cd /usr/local/apache2/bin/

[[email protected] bin]# ./apachectl start

httpd: Syntax error on line 55 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: libmysqlclient.so.15: cannot open shared object file: No such file or directory

解决办法:让所有库自动给连5.0.84的client lib

cd /usr/lib

ln -s /usr/local/mysql/lib/libmysqlclient.so.15 libmysqlclient.so.15

ll | grep mysqls

(1)

启动 apachectl 时出错,说httpd.conf的53行有语法错误.libphp5.so模块无法载入.

错误信息如下:

Syntax error on line 53 of /usr/local/apache2/conf/httpd.conf:

Can not load /usr/local/apache2/modules/libphp5.so into server:

/usr/local/apache2/modules/libphp5.so:

Can't restore segment prot after reloc : Permission denied

解决: apache不能加载外挂php模块这是由SELinux的安全策略配置不当引起的.在Fedora Core 的官方网站上有相关的Apache/SELinux的策略调整文档.如果嫌麻烦,可以直接修改/etc/selinux/config 将SELinux禁用.

(2)

Syntax error on line 79 of /usr/local/httpd/conf/httpd.conf:

AddType requires at least two arguments,a mime type followed by one or more file extensions

解决:要加空格

(3)

启动 httpd:httpd: Syntax error on line 210 of /etc/httpd/conf/httpd.conf: Syntax error on line 6 of /etc/httpd/conf.d/auth_mysql.conf: Cannot load /etc/httpd/modules/mod_auth_mysql.so into server: libmysqlclient.so.15: cannot open shared object file: No such file or directory

[失败]

解决:看见上面的原因可能是我之前卸载rhel自带的mysql的过程中,强制卸载了一些依赖包,解决办法如下:

vi /etc/httpd/conf.d/auth_mysql.conf //进入相关文件,注释掉出错的第六行,解决OK

在设置的DocumentRoot目录下,添加一个phpinfo.php的文件来测试系统,程序

<?

//filename: phpinfo.php

phpinfo();

?>

这时候在客户端浏览器中访问http://localhost/phpinfo.php应该出现php的参数表,至此所有系统安装完毕。

4 测试时发现不能解析php,具体表现为页面空白,但可以解析html(就是能出来apache刚安装好后的提示那个)

解决:<?php

phpinfo();

?>

?后少加了后缀php。这是php.ini没有设置好的原因

; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.

; NOTE: Using short tags should be avoided when developing applications or

; libraries that are meant for redistribution, or deployment on PHP

; servers which are not under your control, because short tags may not

; be supported on the target server. For portable, redistributable code,

; be sure not to use short tags.

short_open_tag = Off

把这个设置为ON也可以解决。。。。。。

*******************************************************************************

再个问题就是:浏览器显示错误信息如下:

Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failed opening required '/usr/local/httpd/htdocs/phpinfo.php' (include_path='.:/usr/local/lib/php') in Unknown on line 0

问题的原因是 : 你的phpinfo.php文件 在这个用户下不具有 可读的权限 通过 ls -l 查看 文件的权限 然后更改权限(添加读权限 chmod +r phpinfo.php)就不会出现这个问题了...

如果看到如的信息即表示成功了

如果重新起动APACHE出现:

Syntax error . line 232 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server:

/usr/local/apache2/modules/libphp4.so: cannot restore segment prot after reloc: Permission denied

那就要按照下面的方法解决:

1.chcon -t texrel_shlib_t /usr/local/apache2/modules/*.so

============================================================

httpd -l

列出编译的模块文件。

httpd -M 查看已经编译了的模块:

如果要支持cgi 功能,请去掉配置文件此行前的注释

#AddHandler cgi-script .cgi

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。