nginx 牛刀小试(第一弹)mini集群

永久链接: http://balzac.iteye.com/blog/2030680

 

1、先看看百科上怎么说的这个玩意儿:

    Nginx(发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:新浪网易 腾讯等。

 

2、windows环境安装包下载:

http://kevinworthington.com/nginx-for-windows/

      文档:http://nginx.org/cn/

 

3、配置:

    A、windows下是一键安装,以下是nginx安装目录C:\nginx\conf\nginx.conf下的文件。

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

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

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

	#################################################
#
	 location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
	    access_log off;
	    expires max;
	 }

	 location ~ /\.ht {
	    deny  all;
	 }

	 location ~* \.(do|action|jsp)$ {
	    proxy_pass       http://localhost:8080;
	    proxy_set_header Host      $host;
	    proxy_set_header X-Real-IP $remote_addr;
	 }
	  
	#################################################

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

}

   B、对添加的配置信息稍作个人见解、

       a、对于http://localhost/ .... jpg|jpeg|gif|css|png|js|ico|html 这些请求,按照配置 它会读取nginx目录下文件

        b、对于http://localhost/ ....do|action|jsp 这些请求,会去请求http://localhost:8080/项目名....do|action|jsp 这个路径

        c、对于找不到的文件 根据配置(error_page  404              404.html;),访问nginx根目录下的404.html

 

4、貌似很牛逼的样子。

     还有一些功能,还需要试试。 

 

ps:下一弹。部署两个tomcat。思考怎么共享session?tomcat集群?。。

 

ps

逐风者1987 逐风者1987回复wbdong820220:哦,是的。你说的对。可以不修改tomcat中的server.xml配置。那样的话,需要把            root   html\www;换成            root   F:\service\apache-tomcat-7.0.16\webapps\ROOT;
2011-07-07 13:42
wbdong820220 wbdong820220不需要修改TOMCAT默认的ROOT目录吧,或者说修改这个跟2者的集成没有关系,nginx只需要能通过URL访问到TOMCAT的资源就行了,至于TOMCAT自身的资源配置情况跟nginx没关系。

     360文档:http://www.360doc.com/content/13/1114/12/7694408_329125489.shtml

你可能感兴趣的:(nginx)