`
xiaobian
  • 浏览: 580569 次
  • 来自: 北京
社区版块
存档分类
最新评论

Ngnix初探

    博客分类:
  • Java
阅读更多

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

分享到:
评论

相关推荐

    Nginx作为动静分离、缓存与负载均衡初探1

    Nginx作为动静分离、缓存与负载均衡初探1

    Nginx源码初探之数据结构 – 基数树数据结构

     Nginx中基数树的实现是一种二叉查找树,具备二叉查找树的所有优点,同时避免了红黑树增删数据是需要通过自身旋转来维持平衡,因此他具有更快的插入、删除速度和更高的内存空间利用率。基数树的key兼顾唯一标识和树...

    nginx平台初探

    众所周知,nginx性能高,而nginx的高性能与其架构是分不开的。那么nginx究竟是怎么样的呢?这一节我们先来初识一下nginx框架吧。nginx在启动后,在unix系统中会以daemon的方式在后台运行,后台进程包含一个master...

    nginx设置资源缓存实战详解

    初探 首先我在 nginx 的根目录下新建了一个 index.html 文件以及 index.js 文件。此时 nginx 的配置文件是长这个样子的: server { listen 8080; server_name localhost; location / { root /Volumes/m

    Nginx服务器中的模块编写及相关内核源码初探

    主要介绍了Nginx服务器中的模块编写及相关源码初探,文中以一个简单的Hello world模块的编写来深入分析Nginx内核所用到的基础函数,需要的朋友可以参考下

    Asp.net Core 初探(发布和部署Linux)

    前言 俗话说三天不学习,赶不上刘少奇。Asp.net Core更新这么长时间一直观望,周末帝都小雨,宅在家看了下Core Web App,顺便搭建了个HelloWorld环境来尝尝鲜,第一次看到.Net Web...Ubuntu Kylin 16.04、nginx “Hello

Global site tag (gtag.js) - Google Analytics