apache配置文件说明及一些指令
标签:
httpd命令和apachectl命令[[email protected] ~]# httpd -h Usage: httpd [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-k start|restart|graceful|graceful-stop|stop] [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X] Options: -D name : define a name for use in <IfDefine name> directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed vhost settings -t -D DUMP_RUN_CFG : show parsed run settings -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t : run syntax check for config files -T : start without DocumentRoot(s) check -X : debug mode (only one worker, do not detach)
apachectl命令和httpd命令基本相同。httpd接受的选项,apachectl都接受。但apachectl还可以省略"-k"选项直接管理httpd进程。
apachectl [-k] start:按照默认路径,读取默认配置文件,并启动httpd。 apachectl [-k] stop:关闭httpd进程。 apachectl [-k] restart:重启httpd进程。 apachectl [-k] graceful-stop:graceful stop,表示让已运行的httpd进程不再接受新请求,并给他们足够的时间处理当前正在处理的事情,处理完成后才退出。所以在进程退出前,日志文件暂时不会关闭,正在进行的连接暂时不会断开。 apachectl [-k] graceful:graceful restart,即graceful-stop+start。 apachectl [-k] configtest:语法检查。 在systemd环境下,还可以使用apachectl status或systemctl status httpd查看httpd进程的详细信息。
配置文件规则和常见指令httpd的核心体现在配置文件,各种功能都通过配置文件来实现。使用rpm包安装的httpd默认配置文件为/etc/httpd/conf/httpd.conf。可以使用httpd -f config_path指定要加载的配置文件。
配置文件中全是一些指令配置,每个指令都是某个模块提供的。以下是配置文件的一些规则:
指令生效方式是从上往下读取,这一点非常非常重要。很多指令的位置强烈建议不要改变,例如Include conf.d/*.conf指令建议不要移动位置。
"#"开头的行为注释行,只能行头注释,不能行中注释。
对大小写不敏感,但是建议指令名称采用"驼峰式"命名。例如ServerRoot,DocumentRoot。
一行写不下的可以使用"\"续行,但是"\"后不能有任何字符,包括空格也不允许。
指令配置格式为"Directive value",例如"ServerRoot /etc/httpd",如果value中包含特殊字符或空格,则必须使用双引号包围。
由于可以通过Include指令包含其他配置文件,又支持各种路径的容器,所以在httpd启动时会先进行配置文件的合并。理解合并规则非常重要,具体见。
Listen指令设置监听套接字。设置方式很简单,包括以下几种情况:
# 监听两个端口 Listen 80 Listen 8000 # 监听套接字绑定在给定地址和端口上 Listen 192.170.2.1:80 Listen 192.170.2.5:8000
ServerRoot指令该指令设置httpd的安装位置,也就是常称之为的basedir,在此目录下应该具有module、logs等目录。rpm安装的httpd的ServerRoot默认为/etc/httpd,编译安装的ServerRoot路径由"--prefix"选项指定,例如/usr/local/apache。
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/40202.html