首页 > 代码库 > Nginx集群模块

Nginx集群模块

ngx_http_upstream_module模块是定义一组服务器的,可以是proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, 和 memcached_pass 指令。

下面写一个考试系统的集群Nginx+Tomcat

新建Nginx的配置文件

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/exam_nginx.conf

编辑exam_nginx.conf,内容如下:

server {
    listen       80;
    server_name exam.windy.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        proxy_pass http://exam.windy.com;
    }

    #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   /usr/share/nginx/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 Apaches document root
    # concurs with nginxs one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
upstream exam.windy.com {
    server 192.168.52.130:8081;
    server 192.168.52.130:8080;
}

 

Nginx集群模块