时间:2021-07-01 10:21:17 帮助过:25人阅读
@echo off



#user  nobody;worker_processes  1;error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  64;}http {    include       mime.types;    default_type  application/octet-stream;    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '    #                  '$status $body_bytes_sent "$http_referer" '    #                  '"$http_user_agent" "$http_x_forwarded_for"';    #access_log  logs/access.log  main;    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    server {        listen       80;        server_name  localhost;        charset gbk;        #access_log  logs/host.access.log  main;        location / {            root   "C:\Program Files\VertrigoServ\www";            index  index.html index.htm index.php;        autoindex on;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        #location ~ \.php$ {        #    root           html;        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;        #    include        fastcgi_params;        #}        location ~ \.php$ {            root   "C:\Program Files\VertrigoServ\www";            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            include        fastcgi_params;        }        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    }    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}    # HTTPS server    #    #server {    #    listen       443;    #    server_name  localhost;    #    ssl                  on;    #    ssl_certificate      cert.pem;    #    ssl_certificate_key  cert.key;    #    ssl_session_timeout  5m;    #    ssl_protocols  SSLv2 SSLv3 TLSv1;    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;    #    ssl_prefer_server_ciphers   on;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}}?
?
压力测试:
下面是用100个并发连接分别去压生产环境中同一负载均衡器VIP下、提供相同服务的两台服务器,一台为Nginx,另一台为Apache,Nginx每秒处理的请求数是Apache的两倍多,Nginx服务器的系统负载、CPU使用率远低于Apache:
  你可以将连接数开到10000~30000,去压Nginx和Apache上的phpinfo.php,这是用浏览器访问Nginx上的phpinfo.php一切正常,而访问Apache服务器的phpinfo.php,则是该页无法显示。4G内存的服务器,即使再优化,Apache也很难在“webbench -c 30000 -t 60 http://xxx.xxx.xxx.xxx/phpinfo.php”的压力情况下正常访问,而调整参数优化后的Nginx可以。
  webbench 下载地址:http://blog.s135.com/post/288/
  注意:webbench 做压力测试时,该软件自身也会消耗CPU和内存资源,为了测试准确,请将 webbench 安装在别的服务器上。
?
| server | Apache | Nginx????? | Lighttpd | 
| Proxy代理 | 非常好 | 非常好 | 一般 | 
| Rewriter | 好 | 非常好 | 一般 | 
| Fcgi | 不好 | 好 | 非常好 | 
| 热部署 | 不支持 | 支持 | 不支持 | 
| 系统压力比较 | 很大 | 很小 | 比较小 | 
| 稳定性 | 好 | 非常好 | 不好 | 
| 安全性 | 好 | 一般 | 一般 | 
| 技术支持 | 非常好 | 很少 | 一般 | 
| 静态文件处理 | 一般 | 非常好 | 好 | 
| Vhosts虚拟主机 | 支持 | 不支持 | 支持 | 
| 反向代理 | 一般 | 非常好 | 一般 | 
| Session sticky | 支持 | 不支持 | 不支持 | 
注:在相对比较大的网站,节约下来的服务器成本无疑是客观的。而有些小型网站往往服务器不多,如果采用 Apache 这类传统 Web 服务器,似乎也还能撑过去。但有其很明显的弊端: Apache 在处理流量爆发的时候(比如爬虫或者是 Digg 效应) 很容易过载,这样的情况下采用 Nginx 最为合适。
建议方案:
Apache 后台服务器(主要处理php及一些功能请求 如:中文url)
Nginx? 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求)
Lighttpd 图片服务器
总体来说,随着nginx功能得完善将使他成为今后web server得主流。
将分别测试3种软件在对动态页面和静态页面请求及并发时的响应时间
l??????? 静态页面 搜狐首页
LIGHTTPD
| n/-c(ab参数) | cpu% | Mem | RequestsperSecond | Time taken for tests | 
| 100000/100 | 64 | 60 | 462.75 | 21.6 | 
| 100000/200 | 67 | 60 | 312.07 | 32.4 | 
| 100000/500 | 83 | 60 | 137.24 | 72.8 | 
| 100000/1000 出现错误丢包 | 94 | 60 | 126.6 | 78.9 | 
NGINX
| n/-c(ab参数) | cpu% | Mem | RequestsperSecond | Time taken for tests | 
| 100000/100 | 34.6 | 140 | 943.66 | 10.597 | 
| 100000/200 | 35.6 | 110 | 924.32 | 10.818 | 
| 100000/500 | 34.3 | 110 | 912.68 | 10.956 | 
| 100000/1000 | 37 | 160 | 832.59 | 12.106 | 
APACHE
| n/-c(ab参数) | cpu% | Mem | RequestsperSecond | Time taken for tests | 
| 100000/100 | 40.6 | 170 | 690.72 | 14.47 | 
| 100000/200 | 41.1 | 180 | 685.39 | 14.59 | 
| 100000/500 | 42.3 | 190 | 633.64 | 15.78 | 
| 100000/1000 | 43.1 | 200 | 547.53 | 18.26 | 
l??????? 动态页面 内部社区首页
LIGHTTPD
| n/-c(ab参数) | cpu% | Mem | RequestsperSecond | Time taken for tests | 
| 1000/100 | 50 | 200 | 33.54 | 29.816 | 
| 1000/200 | 52 | 210 | 30.43 | 32.858 | 
| 1000/500 | 54 | 230 | 25.79 | 38.76 | 
| 1000/1000 | 62 | 250 | 24.83 | 40.28 | 
NGINX
| n/-c(ab参数) | cpu% | Mem | RequestsperSecond | Time taken for tests | 
| 1000/100 | 53.8 | 250 | 83.12 | 12.305 | 
| 1000/200 | 55.8 | 250 | 74.05 | 13.504 | 
| 1000/500 | 56 | 260 | 58.99 | 16.951 | 
| 1000/1000 | 58 | 260 | 43.41 | 23.347 | 
APACHE
| n/-c(ab参数) | cpu% | Mem | RequestsperSecond | Time taken for tests | 
| 100000/100 | 60 | 200 | 27.37 | 36.541 | 
| 100000/200 | 61 | 220 | 23.82 | 41.981 | 
| 100000/500 | 73 | 150 | 20.59 | 48.562 | 
| 100000/1000 | 53 | 200 | 27.18 | 36.796 | 
l??????? PHPINFO函数页
LIGHTTPD
| n/-c(ab参数) | cpu% | Mem | RequestsperSecond | Time taken for tests | 
| 100000/100 | 45 | 20 | 168.06 | 59.504 | 
| 100000/200 | 47 | 22 | 140.64 | 71.103 | 
| 100000/500 | 49 | 24 | 52.80 | 189.386 | 
| 100000/1000 | 在请求到4840时测试测试程序死掉 | 
NGINX
| n/-c(ab参数) | cpu% | Mem | RequestsperSecond | Time taken for tests | 
| 100000/100 | 70 | 120 | 143.46 | 69.706 | 
| 100000/200 | 72 | 130 | 140.57 | 71.140 | 
| 100000/500 | 73 | 150 | 135.87 | 73.601 | 
| 100000/1000 | 77 | 160 | 132.18 | 75.657 | 
APACHE 出现丢包
| n/-c(ab参数) | cpu% | Mem | RequestsperSecond | Time taken for tests | 
| 100000/100 | 70 | 180 | 245.73 | 40.694 | 
| 100000/200 | 72 | 190 | 245.79 | 40.684 | 
| 100000/500 | 75 | 200 | 241.29 | 41.443 | 
| 100000/1000 | 77 | 220 | 236.74 | 42.239 | 
各大网站WEB服务器资源列表
网站名?? 操作系统?? web服务器
1.门户网站类:
搜狐???? LINUX???? ????? apache 1.3.37
新浪???? LINUX???? ????? apache 2.0.54
迅雷???? LINUX???? ????? nginx 0.6.31
163????? LINUX???? ????? apache 2.2.6
2.搜索类
百度????? unknown?? ???? BWS 1.0
Google?? linux??????? ?? gws
Sougou?? FreeBSD??? ?? ??apache 2.2.4
Hao123?? linux??????? ??apache 2.2.4
4. 电子邮箱类
126??????? linux???????? apache
Hotmail??? win2003???? ?microsoft-IIS 6.0
新浪邮箱??? F5 Big-IP??? apache 2.2.8
263??????? linux???????? apache 2.2.6
5. 博客类
新浪博客??? linux????????? nginx 0.5.35
搜狐博客??? linux????????? nginx
迅雷博客