注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

老和山小和尚

敬天爱人

 
 
 

日志

 
 
 
 

[ANNOUCE] nginx_ajp_module_v0.1 - support AJP protocol proxy with Nginx  

2010-06-09 17:09:41|  分类: Nginx |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Name
    nginx_ajp_module - support AJP protocol proxy with Nginx

Status
    This module is at its very early phase of development and considered
    highly experimental. But you're encouraged to test it out on your side
    and report any quirks that you experience.

    We need your help! If you find this module useful and/or interesting,
    please consider joining the development!

Synopsis
    http {

        upstream tomcats {

            server 127.0.0.1:8009 srun_id=jvm1;

            jvm_route $cookie_JSESSIONID reverse;
            keepalive 10;
        }

        server {

            listen 80;

            location / {
                ajp_pass tomcats;
            }
        }

    }

Description
    With this module, Nginx can connect to Tomcat's AJP port directly. The
    backend connections are keepalive, sesstion sticky. The motivation of
    writing these modules is Nginx's high performance and robustness.

Directives
  ajp_buffers
    syntax: *ajp_buffers the_number is_size;*

    default: *ajp_buffers 8 4k/8k;*

    context: *http, server, location*

    This directive sets the number and the size of buffers, into which will
    be read the response, obtained from the ajp server. By default, the size
    of one buffer is equal to the size of two pages. Depending on platform
    this is either 4K, 8K or 16K.

  ajp_buffer_size
    syntax: *ajp_buffer_size the_size;*

    default: *ajp_buffer_size 4k/8k;*

    context: *http, server, location*

    This directive sets the buffersize, into which will be read the first
    part of the response, obtained from the ajp server.

    In this part of response the small response-header is located, as a
    rule.

    By default, the buffersize is equal to the size of one buffer in
    directive "ajp_buffers"; however, it is possible to set it to less.

  ajp_cache
    syntax: *ajp_cache zone;*

    default: *off*

    context: *http, server, location*

    The directive specifies the area which actually is the share memory's
    name for caching. The same area can be used in several places.

  ajp_cache_key
    syntax: *ajp_cache_key line ;*

    default: *none*

    context: *http, server, location*

    The directive sets the key for caching, for example:

    ajp_cache_key localhost:9000$request_uri;

  ajp_cache_methods
    syntax: *ajp_cache_methods [GET HEAD POST];*

    default: *ajp_cache_methods GET HEAD;*

    context: *main,http,location*

    GET/HEAD is syntax sugar, i.e. you can not disable GET/HEAD even if you
    set just

    ajp_cache_methods POST;

  ajp_cache_min_uses
    syntax: *ajp_cache_min_uses n;*

    default: *ajp_cache_min_uses 1;*

    context: *http, server, location*

    TODO: Description.

  ajp_cache_path
    syntax: *ajp_cache_path /path/to/cache [levels=m:n keys_zone=name:time
    inactive=time clean_time=time];*

    default: *none*

    context: *http, server, location*

    TODO: Description.

  ajp_cache_use_stale
    syntax: *ajp_cache_use_stale
    [updating|error|timeout|invalid_header|http_500];*

    default: *ajp_cache_use_stale off;*

    context: *http, server, location*

    TODO: Description.

  ajp_cache_valid
    syntax: *ajp_cache_valid [http_error_code|time];*

    default: *none*

    context: *http, server, location*

    TODO: Description.

  ajp_connect_timeout
    syntax: *ajp_connect_timeout time;*

    default: *ajp_connect_timeout 60s;*

    context: *http, server, location*

    This directive assigns a timeout for the connection to the upstream
    server. It is necessary to keep in mind that this time out cannot be
    more than 75 seconds.

    This is not the time until the server returns the pages, this is the
    ajp_read_timeout statement. If your upstream server is up, but hanging
    (e.g. it does not have enough threads to process your request so it puts
    you in the pool of connections to deal with later), then this statement
    will not help as the connection to the server has been made.

  ajp_header_packet_buffer_size
    syntax: *ajp_header packet_buffer_size;*

    default: *ajp_header_packet_buffer_size 8k;*

    context: *http, server, location*

    Set the buffer size of Forward Request packet. The range is (0, 2^16).

  ajp_hide_header
    syntax: *ajp_hide_header name;*

    context: *http, server, location*

    By default, Nginx does not pass headers "Status" and "X-Accel-..." from
    the AJP process back to the client. This directive can be used to hide
    other headers as well.

    If the headers "Status" and "X-Accel-..." must be provided, then it is
    necessary to use directive ajp_pass_header to force them to be returned
    to the client.

  ajp_ignore_headers
    syntax: *ajp_ignore_headers name [name ...];*

    default: *none*

    context: *http, server, location*

    This directive(0.7.54+) prohibits the processing of the header lines
    from the proxy server's response.

    It can specify the string as "X-Accel-Redirect", "X-Accel-Expires",
    "Expires" or "Cache-Control".

  ajp_ignore_client_abort
    syntax: *ajp_ignore_client_abort on|off;*

    default: *ajp_ignore_client_abort off;*

    context: *http, server, location*

    This directive determines if current request to the AJP-server must be
    aborted in case the client aborts the request to the server.

  ajp_intercept_errors
    syntax: *ajp_intercept_errors on|off;*

    default: *ajp_intercept_errors off;*

    context: *http, server, location*

    This directive determines whether or not to transfer 4xx and 5xx errors
    back to the client or to allow Nginx to answer with directive
    error_page.

    Note: You need to explicitly define the error_page handler for this for
    it to be useful. As Igor says, "nginx does not intercept an error if
    there is no custom handler for it it does not show its default pages.
    This allows to intercept some errors, while passing others as are."

  ajp_next_upstream
    syntax: *ajp_next_upstream
    [error|timeout|invalid_header|http_500|http_502|http_503|http_504|http_4
    04|off];*

    default: *ajp_next_upstream error timeout;*

    context: *http, server, location*

    Directive determines, in what cases the request will be transmitted to
    the next server:

    *   error — an error has occurred while connecting to the server,
        sending a request to it, or reading its response;

    *   timeout — occurred timeout during the connection with the server,
        transfer the request or while reading response from the server;

    *   invalid_header — server returned a empty or incorrect answer;

    *   http_500 — server returned answer with code 500

    *   http_502 — server returned answer with code 502

    *   http_503 — server returned answer with code 503

    *   http_504 — server returned answer with code 504

    *   http_404 — server returned answer with code 404

    *   off — it forbids the request transfer to the next server
        Transferring the request to the next server is only possible when
        nothing has been transferred to the client -- that is, if an error
        or timeout arises in the middle of the transfer of the request, then
        it is not possible to retry the current request on a different
        server.

  ajp_max_data_packet_size
    syntax: *ajp_max_data_packet_size size;*

    default: *ajp_max_data_packet_size 8k;*

    context: *http, server, location*

    Set the maximum size of AJP's Data packet. The range is [8k, 2^16];

  ajp_max_temp_file_size
    syntax: *ajp_max_temp_file_size size;*

    default: *ajp_max_temp_file_size 1G;*

    context: *http, server, location, if*

    The maximum size of a temporary file when the content is larger than the
    proxy buffer. If file is larger than this size, it will be served
    synchronously from upstream server rather than buffered to disk. If
    ajp_max_temp_file_size is equal to zero, temporary files usage will be
    disabled.

  ajp_pass
    syntax: *ajp_pass ajp-server*

    default: *none*

    context: *location, if in location*

    Directive assigns the port or socket on which the AJP-server is
    listening. Port can be indicated by itself or as an address and port,
    for example:

    ajp_pass localhost:9000;

    using a Unix domain socket:

    ajp_pass unix:/tmp/ajp.socket;

    You may also use an upstream block.

    upstream backend { server localhost:1234; }

    ajp_pass backend;

  ajp_pass_header
    syntax: *ajp_pass_header name;*

    context: *http, server, location*

    TODO: Description.

  ajp_pass_request_headers
    syntax: *ajp_pass_request_headers [ on | off ];*

    default: *ajp_pass_request_headers on;*

    context: *http, server, location*

    TODO: Description.

  ajp_pass_request_body
    syntax: *ajp_pass_request_body [ on | off ] ;*

    default: *ajp_pass_request_body on;*

    context: *http, server, location*

    TODO: Description.

  ajp_read_timeout
    syntax: *ajp_read_timeout time;*

    default: *ajp_read_timeout_time 60*

    context: *http, server, location*

    Directive sets the amount of time for upstream to wait for a ajp process
    to send data. Change this directive if you have long running ajp
    processes that do not produce output until they have finished
    processing. If you are seeing an upstream timed out error in the error
    log, then increase this parameter to something more appropriate.

  ajp_send_lowat
    syntax: *ajp_send_lowat [ on | off ];*

    default: *ajp_send_lowat off;*

    context: *http, server, location, if*

    This directive set SO_SNDLOWAT. This directive is only available on
    FreeBSD

  ajp_send_timeout
    syntax: *ajp_send_timeout time;*

    default: *ajp_send_timeout 60;*

    context: *http, server, location*

    This directive assigns timeout with the transfer of request to the
    upstream server. Timeout is established not on entire transfer of
    request, but only between two write operations. If after this time the
    upstream server will not take new data, then nginx is shutdown the
    connection.

  ajp_store
    syntax: *ajp_store [on | off | path] ;*

    default: *ajp_store off;*

    context: *http, server, location*

    This directive sets the path in which upstream files are stored. The
    parameter "on" preserves files in accordance with path specified in
    directives *alias* or *root*. The parameter "off" forbids storing.
    Furthermore, the name of the path can be clearly assigned with the aid
    of the line with the variables:

    ajp_store /data/www$original_uri;

    The time of modification for the file will be set to the date of
    "Last-Modified" header in the response. To be able to safe files in this
    directory it is necessary that the path is under the directory with
    temporary files, given by directive ajp_temp_path for the data location.

    This directive can be used for creating the local copies for dynamic
    output of the backend which is not very often changed, for example:

    location /images/ {

        root                 /data/www;
        error_page           404 = /fetch$uri;

    }

    location /fetch {

        internal;

        ajp_pass           backend;
        ajp_store          on;
        ajp_store_access   user:rw  group:rw  all:r;
        ajp_temp_path      /data/temp;

        alias             /data/www;

    }

    To be clear ajp_store is not a cache, it's rather mirror on demand.

  ajp_store_access
    syntax: *ajp_store_access users:permissions [users:permission ...];*

    default: *ajp_store_access user:rw;*

    context: *http, server, location*

    This directive assigns the permissions for the created files and
    directories, for example:

    ajp_store_access user:rw group:rw all:r;

    If any rights for groups or all are assigned, then it is not necessary
    to assign rights for user:

    ajp_store_access group:rw all:r;

  ajp_temp_path
    syntax: *ajp_temp_path dir-path [ level1 [ level2 [ level3 ] ] ] ;*

    default: *$NGX_PREFIX/ajp_temp*

    context: *http, server, location*

    This directive works like client_body_temp_path to specify a location to
    buffer large proxied requests to the filesystem.

  ajp_temp_file_write_size
    syntax: *ajp_temp_file_write_size size;*

    default: *ajp_temp_file_write_size ["#ajp buffer size"] * 2;*

    context: *http, server, location, if*

    Sets the amount of data that will be flushed to the ajp_temp_path when
    writing. It may be used to prevent a worker process blocking for too
    long while spooling data.

  jvm_route
    syntax: *jvm_route $cookie_SESSION_COOKIE[|session_url] [reverse]*

    default: *none*

    context: *upstream*

    This directive comes from ngx_http_upstream_jvm_route_module
    (<http://code.google.com/p/nginx-upstream-jvm-route/>).

    '$cookie_SESSION_COOKIE' specifies the session cookie name(0.7.24+).
    'session_url' specifies a different session name in the URL when the
    client does not accept a cookie. The session name is case-insensitive.
    In this module, if it does not find the session_url, it will use the
    session cookie name instead. So if the session name in cookie is the
    name with its in URL, you don't need give the session_url name.

    With scanning this cookie, the module will send the request to right
    backend server. As far as I know, the resin's srun_id name is in the
    head of cookie. For example, requests with cookie value 'a***' are
    always sent to the server with the srun_id of 'a'. But tomcat's
    JSESSIONID is opposite, which is like '***.a'. The parameter of
    'reverse' specifies the cookie scanned from tail to head.

    If the request fails to be sent to the chosen backend server, It will
    try another server with the Round-Robin mode until all the upstream
    servers tried. The directive ajp_next_upstream can specify in what cases
    the request will be transmitted to the next server. If you want to force
    the session sticky, you can set 'ajp_next_upstream off'.

  jvm_route_status
    syntax: *jvm_route_status upstream_name*

    default: *none*

    *'context:* *location*

    This directive comes from ngx_http_upstream_jvm_route_module
    (<http://code.google.com/p/nginx-upstream-jvm-route/>).

    Set the location of pages return the status of the jvm_route peers.
    Example: location status { jvm_route_status backend; }

  keepalive
    syntax: *keepalive <num> [single]*

    default: *none*

    context: *upstream*

    Switches on keepalive module for the upstream in question. This
    directive comes from ngx_http_upstream_keepalive_module
    (<http://mdounin.ru/hg/ngx_http_upstream_keepalive/>).

    Parameters:

    *   num: Maximum number of connections to cache. If there isn't enough
        room to cache new connections - last recently used connections will
        be kicked off the cache.

    *   single: Treat everything as single host. With this flag connections
        to different backends are treated as equal.

  server(in upstream)
    This directive comes from ngx_http_upstream_jvm_route_module
    (<http://code.google.com/p/nginx-upstream-jvm-route/>).

    Main syntax is the same as the official directive. This module add these
    parameters:

    *   'srun_id': identifies the backend JVM's name by cookie. The default
        srun_id's value is 'a'. The name can be more than one letter.

    *   'max_busy': the maximum of active connections with the backend
        server. The default value is 0 which means unlimited. If the
        server's active connections is higher than this parameter, it will
        not be chosen until the server is less busier. If all the servers
        are busy, Nginx will return 502.

    NOTE: This module does not support the parameter of 'backup' yet.

Installation
    Download the latest version of the release tarball of this module from
    github (<http://github.com/yaoweibin/nginx_ajp_module>)

    Grab the nginx source code from nginx.org (<http://nginx.org/>), for
    example, the version 0.7.65 (see nginx compatibility), and then build
    the source with this module:

        $ wget 'http://nginx.org/download/nginx-0.7.65.tar.gz'
        $ tar -xzvf nginx-0.7.65.tar.gz
        $ cd nginx-0.7.65/
        $ patch -p1 < /path/to/nginx_ajp_module/ajp.patch

        $ ./configure --add-module=/path/to/nginx_ajp_module

        $ make
        $ make install

Compatibility
    *   My test bed is 0.7.65 and 0.8.34.

TODO
    *   SSL

    *   Add AJP health check

Known Issues
    *   Developing

Changelogs
  v0.1
    *   first release

Authors
    Weibin Yao(姚伟斌) *yaoweibin at gmail dot com*

Copyright & License
    This README template copy from agentzh (<http://github.com/agentzh>).

    I borrowed a lot of codes from Fastcgi module of Nginx. This part of
    code is copyrighted by Igor Sysoev. And the AJP library code from
    apache's mod_ajp_proxy
    (<http://httpd.apache.org/docs/trunk/mod/mod_proxy_ajp.html>). Thanks
    for their hard work.

    This module is licensed under the BSD license.

    Copyright (C) 2010 by Weibin Yao <yaoweibin@gmail.com>.

    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

    *   Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.

    *   Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
    TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  评论这张
 
阅读(3404)| 评论(6)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018