“Apache HTTP Server”是开源软件项目的杰出表明,基于标准的HTTP网络协议提供网页浏览服务,在Web服务器领域中长期保持着超过半数的份额。Apache服务器能够运行在Linux,UNIX,Windows等多种操做平台中html
Centos6:httpd2.2java
Centos7:httpd2.4web
/etc/httpd/conf/httpd.conf apache
/etc/httpd/conf.d/*.conf编程
/etc/rc.d/init.d/httpd vim
配置文件:/etc/sysconfig/httpd浏览器
/usr/sbin/httpd
/usr/sbin/httpd.event
/usr/sbin/httpd.worker 安全
/var/log/httpd 服务器
/var/log/httpd/access_log 访问日志 网络
/var/log/httpd/error_log 错误日志
/var/www/html
/usr/lib64/httpd/modules
[root@Server ~]# grep "Section" /etc/httpd/conf/httpd.conf ### Section 1: Global Environment ### Section 2: 'Main' server configuration ### Section 3: Virtual Hosts
directive value
directive: 不区分字符大小写
value:为路径时,取决于文件系统
1 [root@Server ~]# yum -y install httpd httpd-manual
[root@Server ~]# vim /etc/httpd/conf/httpd.conf #ServerName www.example.com:80 ServerName localhost:80
[root@Server ~]# service httpd start
正在启动 httpd:
[root@Server ~]# service iptables stop [root@Server ~]# setenforce 0
[root@Server ~]# service httpd restart
中止 httpd: [肯定]
正在启动 httpd: [肯定]
ServerRoot "/etc/httpd" //apache软件安装的位置。其它指定的目录若是没有指定绝对路径,则目录是相对于该目录。 PidFile run/httpd.pid //第一个httpd进程(全部其余进程的父进程)的进程号文件位置。
Timeout 60 //设置链接超时,参数timeout,当链接超过必定的空闲时间,就会自动断开
KeepAlive On //设置keepalive,提升网络效率,默认是关闭的
MaxKeepAliveRequests 100 //设置keepaliverequest,设置为0 的时候没有限制,不过最好仍是用默认值,或者本身根据状况来改变
Listen 80 //服务器监听的端口号。 ServerName localhost:80 //主站点名称(网站的主机名)。 ServerAdmin admin@clusting.com //管理员的邮件地址。 DocumentRoot "/var/www/htdocs" //主站点的网页存储位置。
DirectoryIndex index.html index.html.var //设置网站主页文件
AddDefaultCharset UTF-8 //设置字符集,参数AddDefaultCharset,建议最好设置utf-8,这是通用的。
<Directory "/var/www/htdocs"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory>
在上面这段目录属性配置中,主要有下面的选项:
ExecCGI: 在该目录下容许执行CGI脚本。
FollowSymLinks: 在该目录下容许文件系统使用符号链接。
Indexes: 当用户访问该目录时,若是用户找不到DirectoryIndex指定的主页文件(例如index.html),则返回该目录下的文件列表给用 户。
SymLinksIfOwnerMatch: 当使用符号链接时,只有当符号链接的文件拥有者与实际文件的拥有者相同时才能够访问。
None: 当AllowOverride被设置为None时。不搜索该目录下的.htaccess文件(能够减少服务器开销)。
All: 在.htaccess文件中可使用全部的指令。
Allow:容许访问的主机列表(可用域名或子网,例如:Allow from 192.168.0.0/16)。
Deny:拒绝访问的主机列表。
apache2主要的优点就是对多处理器的支持更好,在编译时同过使用–with-mpm选项来决定apache2的工做模式。若是知道当前的apache2使用什么工做机制,能够经过httpd -l命令列出apache的全部模块,就能够知道其工做方式:
prefork:若是httpd -l列出prefork.c,则须要对下面的段进行配置:
<IfModule prefork.c> StartServers 5 #启动apache时启动的httpd进程个数。 MinSpareServers 5 #服务器保持的最小空闲进程数。 MaxSpareServers 10 #服务器保持的最大空闲进程数。 MaxClients 150 #最大并发链接数。 MaxRequestsPerChild 1000 #每一个子进程被请求服务多少次后被kill掉。0表示不限制,推荐设置为1000。 </IfModule>