- 简介
- 第一章 - 关于 CD
- 第二章 - 基本命令
- Hack-7 Grep
- Hack-8 Grep 与正则表达式
- Hack-9 Find 命令
- Hak-10 重定向
- Hack-11 Join 命令
- Hack-12 Tr 命令
- Hack-13 Xargs 命令
- Hack-14 Sort 命令
- Hack-15 Uniq 命令
- Hack-16 Cut 命令
- Hack-17 Stat 命令
- Hack-18 Diff 命令
- Hack-19 Ac 命令
- Hack-20 让命令在后台执行
- Hack-21 Sed 替换基础
- Hack-22 Awk 简介
- Hack-23 VIM 基本入门
- Hack-24 Chmod 命令
- Hack-25 Tail -f -f
- Hack-26 Less 命令
- Hack-27 Wget 下载器
- 第三章 - SSH 技巧
- 第四章 - 日期设置
- 第五章 - PS* 介绍
- 第六章 - 压缩和打包
- 第七章 - 历史命令
- 第八章 - 系统任务管理
- 第九章 - 安装软件
- 第十章 - LAMP 套装
- 第十一章 - Bash 脚本
- 第十二章 - 系统性能监控
- 第十三章 - 额外的技巧
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
Hack-81 Apachectl 和 Httpd 技巧
Apachectl 和 Httpd 技巧
安装完 Apache2 之后,如果你想用 apachectl
和 httpd
来发挥他们最大的潜能,那你就不能仅仅使用 start
, stop
, status
了. 下面的九个例子向你介绍了如何高效的使用它们。
给 apachectl 设置一个不同的 httpd.conf
文件
一般来说,当你需要设置一个不同的 apache2 指令时,你需要修改原来的 httpd.conf
文件,但是利用下面的方法,你就可以新建一个,而不是修改原来的,以达到测试的目的。
apachectl -f conf/httpd.conf.debug
# or
httpd -k start -f conf/httpd.conf.debug
看一下进程:
ps -ef | grep http
root 25080 1 0 23:26 00:00:00 /usr/sbin/httpd -f conf/httpd.conf.debug
apache 25099 25080 0 23:28 00:00:00 /usr/sbin/httpd -f conf/httpd.conf.debug
如果这个 conf/httpd.conf.debug
文件没有问题的话,你就可以把它复制为 conf/httpd.conf
, 然后重启 apache:
# cp httpd.conf.debug httpd.conf
# apachectl stop
# apachectl start
不修改 httpd.conf
文件就更换网页根目录
用 -c
选项可以很简单的更改网页的根目录,而不必修改配置文件。
# httpd -k start -c "DocumentRoot /var/www/html_debug/"
提升日志记录的等级
用 -e
选项可以更改 apache2 记录的日志等级
# httpd -k start -e debug
[Sun Aug 17 13:53:06 2008] [debug] mod_so.c(246): loaded module auth_basic_module
[Sun Aug 17 13:53:06 2008] [debug] mod_so.c(246): loaded module auth_digest_module
可用的等级有: debug, info, notice, warn, error, crit, alert, emerg
.
显示 apache 已编译的模块
# httpd -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c
显示 apache 加载的模块(动态/静态)
上一个 -l
选项只显示了静态编译过的模块,这个 -M
则会显示动态模块和共享模块。
# httpd -M
Loaded Modules:
core_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
auth_basic_module (shared)
auth_digest_module (shared)
authn_file_module (shared)
authn_alias_module (shared)
Syntax OK
显示 httpd.conf
内所有可用的指令
这个 -L
的选项类似于 httpd 的帮助扩展,他会显示 httpd.conf 中可用的变量及其参数,
# httpd -L
HostnameLookups (core.c)
"on" to enable, "off" to disable reverse DNS lookups, or
"double" to enable double-reverse DNS lookups
Allowed in *.conf anywhere
ServerLimit (prefork.c)
Maximum value of MaxClients for this run of Apache
Allowed in *.conf only outside <Directory>, <Files> or
<Location>
KeepAlive (http_core.c)
Whether persistent connections should be On or Off
Allowed in *.conf only outside <Directory>, <Files> or
<Location>
LoadModule (mod_so.c)
a module name and the name of a shared object file to load
it from
Allowed in *.conf only outside <Directory>, <Files> or
<Location>
检测修改过的 httpd.conf
是否有错误
当我们新更改过 apache 的配置文件后,我们应该先检测一下里面是否有错误的语法或者配置不正确的参数,用 -t
这个参数:
# httpd -t -f conf/httpd.conf.debug
httpd: Syntax error on line 148 of
/etc/httpd/conf/httpd.conf.debug:
Cannot load /etc/httpd/modules/mod_auth_basicso into
server:
/etc/httpd/modules/mod_auth_basicso: cannot open shared
object file: No such file or directory
Once you fix the issue, it will display Syntax OK.
# httpd -t -f conf/httpd.conf.debug
Syntax OK
显示 httpd
编译参数
# httpd -V
Server version: Apache/2.2.9 (Unix)
Server built:
Jul 14 2008 15:36:56
Server's Module Magic Number: 20051115:15
Server loaded:
APR 1.2.12, APR-Util 1.2.12
Compiled using: APR 1.2.12, APR-Util 1.2.12
Architecture: 32-bit
Server MPM: Prefork
threaded:
forked:
no
yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="logs/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="logs/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
... ...
... ...
或者用 -v
显示很少的信息:
# httpd -v
Server version: Apache/2.2.9 (Unix)
Server built:
Jul 14 2008 15:36:56
按需加载特定的模块
有时候你并不需要加载全部的模块,你只需要加载某个特定的模块,怎么做呢?
还是修改 httpd.conf
文件:
<IfDefine load-ldap>
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
</IfDefine>
当你测试 ldap 的时候你会想加载所有与 ldap 有关的模块,所以:
# httpd -k start -e debug -Dload-ldap -f
/etc/httpd/conf/httpd.conf.debug
[Sun Aug 17 14:14:58 2008] [debug] mod_so.c(246): loaded
module ldap_module
[Sun Aug 17 14:14:58 2008] [debug] mod_so.c(246): loaded
module authnz_ldap_module
[Note: Pass -Dload-ldap, to load the ldap modules into
Apache]
注意 -D
参数哦~
# apachectl start
[Note: Start the Apache normally, if you don't want to
load the ldap modules.]
本书简介:
- Linux 进阶技巧
- 巧妙的命令组合
- Bash 某些技巧
- 一共一百零一个(包括充数的)
- 最后有个奖励章(额外技巧)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论