宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

apache   worker/prefork

 /application/apache/bin/apachectl -l | sed -n '/worker\|prefork/p'

  worker.c

Server MPM:     Worker

./configure    –with-mpm=worke  //编译时指定,,默认是prefork


prefork  默认

使用多个子进程,每个子进程只有一个线程

效率高,稳定,安全,比worker消耗资源多

vim  /application/apache/conf/extra/httpd-mpm.conf

<IfModule mpm_prefork_module>

    StartServers        10               //服务启动进程数            

    MinSpareServers      10          //最小空闲数量

    MaxSpareServers     15           //最大空闲数量

    ServerLimit       2000

    MaxClients          1000              //最大进程  并发

    MaxRequestsPerChild   5000        //子进程处理的最大进程数           0=不限制

</IfModule>

ps -ef | grep http| grep -v grep | wc -l           //查看并发连接

6


worker    线程与进程的结合

vim  /application/apache/conf/extra/httpd-mpm.conf

<IfModule mpm_worker_module>

    StartServers          2             

    MaxClients           2000           //并发的客户端连接数量

    ServerLimit       25   //总进程数

    MinSpareThreads     50

    MaxSpareThreads     200

    ThreadLimit         200

    ThreadsPerChild        100   // 持续的每个服务器的工作线程数

    MaxRequestsPerChild   0   // 单个子进程累计最多处理到少个请求,默认0,不限制的意思

</IfModule>


MaxClient <=  ServerLimit*  ThreadsPerChild

MaxClient %ThreadsPerChild  =0


cat /application/apache/conf/extra/httpd-default.conf

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5

UseCanonicalName Off

AccessFileName .htaccess

ServerTokens Full

ServerSignature On

HostnameLookups Off


并发连接数

pstree -a | grep http |grep -v grep  | wc -l

110


apache  web 服务防盗链


<Directory "/usr/local/apache2/htdocs/cfan/pic/">

             RewriteEngine  on

             RewriteCond %{HTTP_REFERER} !^http://网站域名/.*$ [NC]

             RewriteRule .*\.(gif|jpg)$   http://代替图标 [R,NC]

</Directory>


Nginx防盗链的配置

location ~* \.(gif|jpg|png|swf|flv|bmp)$ {

 valid_referers none blocked *.hequan.com hequan z.com;

  if ($invalid_referer) {

   #rewrite ^/ http://www.hequan .com/403.html;

   return 403;

  }

}


转载于:https://blog.51cto.com/hequan/1770655