您的位置:首页 > 运维架构 > Tomcat

linux+nginx+tomcat集群-简单配置文件

2016-01-29 10:38 776 查看
#Nginx所用用户和组,window下不指定  

user  nobody;  

  

#工作的子进程数量(通常等于CPU数量或者2倍于CPU)  

worker_processes  1;  

  

#错误日志存放路径  

#error_log  logs/error.log;  

#error_log  logs/error.log  notice;  

error_log  logs/error.log  info;  

  

#指定pid存放文件  

pid        logs/nginx.pid;  

  

  

events {  

#使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。  

use epoll;  

  

#允许最大连接数    

worker_connections  1024;  

}  

  

  

http {  

    #mine.types内定义各文件类型映像  

    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 tomcats {  

        server localhost:8080 weight=1;  

        server localhost:9080 weight=1;  

          

        #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。  

        #同一机器在多网情况下,路由切换,ip可能不同 ---测试的时候可以禁止此项,轮转更明显 

        ip_hash;  

    }     

  

    server {  

        listen       80;  

        server_name  localhost;  

  

        #charset koi8-r;  

  

        #access_log  logs/host.access.log  main;  

  

        location / {  

            index  index.shtml;  

            proxy_pass  http://tomcats;  

            proxy_set_header    X-Real-IP   $remote_addr;  

            client_max_body_size    100m;  

        }  

  

#配置动静态分离

#location ~ \.(jsp)?$ {

       
#proxy_pass http://tomcats;
        #proxy_set_header Host $host;

        #proxy_set_header X-Real-IP $remote_addr;

        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        #proxy_connect_timeout       100;

        #proxy_read_timeout          100;

        #proxy_send_timeout          100;
#}
#location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {

        #  expires 30d;

        #  root  /usr/local/nginx/html;

        #}

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

    #    }  

    #}  

  

}  

检查nginx的配置
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t -c /usr/nginx/conf/nginx.conf


四、启动测试
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/tomcats/tomcat-a/bin/startup.sh
/usr/local/tomcats/tomcat-b/bin/startup.sh
/usr/local/tomcats/tomcat-c/bin/startup.sh


停止服务
/usr/local/tomcats/tomcat-a/bin/shutdown.sh
/usr/local/tomcats/tomcat-b/bin/shutdown.sh
/usr/local/tomcats/tomcat-c/bin/shutdown.sh
pkill -9 nginx
重启服务
/usr/local/nginx/sbin/nginx -s reload
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: