apache是现在主流的web服务,以其稳定高效广受欢迎,下面是“nginxs小白”以前总结的一些笔记,仅供参考学习; Apache目录树: [iyunv@www ~]# tree /etc/httpd/ 安装目录 /etc/httpd/ |-- conf | |-- httpd.conf | `-- magic |-- conf.d | |-- README | `-- proxy_ajp.conf |-- logs -> ../../var/log/httpd |-- modules ->../../usr/lib/httpd/modules `-- run -> ../../var/run
apache有两种模式: 进程模式和线程模式; 进程模式: 每个用户连接时都会分配一个单独的进程; 线程模式: 用户请求连接时会在进程中分配一个单独的线程; 区别: 进程模式每个进程有多个子进程,每个子进程只控制一个线程而 线程模式每个进程也是多个子进程,但是它每个子进程控制多个线 程,而每个线程控制一个请求和链接的话,同样的请求线程模式比 进程模式更节省资源; 那么大家就会说都用线程模式吧,这样就有带你片面啦!!! 既然存在就由他的理由的! 线程模式虽然比进程模式节省资源但是它也带来了自己不稳定因素, 就是这个进程一旦一个线程垮掉,该进程和所有线程就会垮,随之而来的损失也是巨大。
[iyunv@www~]# vim /etc/httpd/conf/httpd.conf ### Section 1:Global Environment ServerRoot"/etc/httpd" Apache安装目录 PidFilerun/httpd.pid 进程文件 Listen 80 监听端口 客户访问:http:192.168.2.115:81 LoadModuleauth_basic_module modules/mod_auth_basic.so 加载模块 Includeconf.d/*.conf 包含conf.d下的*.conf文件 User apache 运行Apache的用户 Group apache 运行Apache的用户组
两种运行模式: [iyunv@www ~]# httpd –l 查看httpd进程当前模式,源码使用安装目录sbin命令同理 Compiled inmodules: core.c prefork.c 当前为进程模式 http_core.c mod_so.c
# prefork MPM(1)进程模式 <IfModule prefork.c> StartServers 10 初始建立的进程数(1个父进程,8个子进程) MinSpareServers 10 最小空闲的进程数 MaxSpareServers 15 最大空闲的进程数 ServerLimit 2000 服务器最大并发连接限制 MaxClients 1500 服务器最大并发访问量 MaxRequestsPerChild 4000 每个子进程在其生命周期内允许响应的最大请求数,达到会结束,0永不 </IfModule>
# worker MPM (2)线程模式 <IfModule worker.c> StartServers 2 初始进程池的进程数 MaxClients 2000 最大线程数 MinSpareThreads 100 最小空闲的线程数 MaxSpareThreads 200 最大空闲的线程数 ThreadsPerChild 50 单进程建立的线程数 MaxRequestsPerChild 0 单个子进程在其生命周期内允许响应的最大请求数,达到会结束,0永不 </IfModule>
切换模式 [iyunv@www ~]# cd/usr/sbin [iyunv@www sbin]#ls httpd* httpd httpd.event httpd.worker
[iyunv@www sbin]#mv httpd httpd.prefork [iyunv@www sbin]#cp httpd.worker httpd [iyunv@www sbin]# httpd -l Compiled in modules: core.c worker.c 进程模式 http_core.c mod_so.c [iyunv@www sbin]#ps aux |grep httpd root 4326 0.0 0.1 10184 3144 ? Ss 14:23 0:00 /usr/sbin/httpd apache 4327 0.0 0.1 286820 2700 ? Sl 14:23 0:00 /usr/sbin/httpd apache 4329 0.0 0.1 286820 2704 ? Sl 14:23 0:00 /usr/sbin/httpd root 4387 0.0 0.0 4264 672 pts/1 R+ 14:23 0:00 grep httpd 切回到进程模式,并默认开启两个进程
### Section 2: 'Main' server configuration### 主网站,默认网站配置 ServerAdmin root@localhost 管理员mail ServerName www.example.com 网站名 DocumentRoot "/var/www/html" 网站主目录 以下设置/var/www/html访问权限 <Directory "/var/www/html"> Options IndexesFollowSymLinks Indexes 索引目录,(没有默认主页时) FollowSymLinks 支持符号链接 AllowOverride None 是否开启限制 Order deny,allow 规则:先拒绝, 后允许 Deny from all 只允许nginxs.blog.访问 Allow from nginxs.blog. </Directory> DirectoryIndex index.html index.html.var 设置默认主页 ErrorLog logs/error_log 错误日志 CustomLog logs/access_log combined 访问日志 Alias/icons/ "/var/www/icons/" 目录别名 AddDefaultCharsetUTF-8 设置字符集
|