Ngnix初探

Nginx是什么?

 

     Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。

 

Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor

 

将源代码以类BSD许可证的形式发布。

谁在使用Nginx?


  Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx 作为 Web 服务器的网站也越来越多,其中包括新浪

 

博客、新浪播客网易新闻等门户网站频道,六间房56.com等视频分享网站,Discuz!官方论坛水木社区等知名论

 

坛,豆瓣YUPOO相册海内SNS迅雷在线等新兴Web 2.0网站。


相关链接:
  

Nginx 的官方中文维基:http://wiki.nginx.org/NginxChs

Nginx 的官方站点: http://nginx.net/

 

 

安装Nginx:

 

由于我的机器上没有*nix环境,所以只能使用Windows版本的Nginx安装测试版本。 使用的Ngnix版本为0.7.59【目前为最新稳定版 2009-06-15】 下载见附件,或者自己去http://sysoev.ru/nginx/nginx-0.7.59.zip下载。

 

下载后把文件解压缩到一个目录中就可以使用了。

解压缩后的目录:

Nginx.exe 为主程序, temp为程序运行时的临时文件夹,logs为访问日志的文件夹,html为两个静态html文件,docs为doc文件夹,conf为配置文件夹,contrib文件夹中有两个perl脚本。

 

启动ngnix的命令: start nginx

关闭ngnix的命令: nginx -s stop

配置文件ngnix.conf正确性判断的命令: nginx -t

 

conf/nginx.conf 为唯一的配置文件

 

配置负载均衡:

 upstream mysvr {
                 server 192.168.0.100:8080 weight=10;
                 server 192.168.0.200:8080 weight=20; 
    }

 

在server的Location域:

添加    proxy_pass http://mysvr;

 

配置单机访问:在server的location域添加 proxy_pass http://192.168.0.100:8080;

 

 

完整的配置文件:

 

#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  1024;
}


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;
    upstream mysvr {
	server 192.168.0.100:8080 weight=10;
	server 192.168.0.200:8080 weight=20;	
    }
	
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
	    #proxy_pass http://192.168.0.100:8080;
	    proxy_pass http://mysvr;
        }

        #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;
        #}

        # 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;
    #    }
    #}

}

 

 

说明:写此文的时候该死的IE死掉了,还好JavaEye有自动保存的功能不让还得从头写。

 

 

参考:http://blog.s135.com/nginx_php_v5/

 

压力测试工具WebBench: http://www.oschina.net/c/article/10526

 

压力测试工具 : http://blog.alexa-pro.cn/?p=445

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值