天天看点

windows 下 ngix + tomcat 集群

第一步: 下载: nginx nginx 下载地址: http://nginx.org/en/download.html tomcat 下载地址: http://tomcat.apache.org/download-70.cgi 第二步:配置 第三步,开启 新建文件夹: nginx+tomcat  将两个文件放在当前文件夹 3.1 解压 nginx ,解压导当前文件夹 3.2 进入目录 在 nginx 目录下,找到 nginx.exe 双击 3.3 查看进程

windows 下 ngix + tomcat 集群

  结束 nginx 进程: 3.3 . 1 直接点击结束 通过命令: 快速停止或关闭 nginx 命令: nginx -s stop 正常停止或关闭 nginx 命令: nginx -s quit 配置文件修改重装载命令: nginx -s reload 3.4 测试访问 显示 welcome to nginx 说明成功

windows 下 ngix + tomcat 集群

  4. 打包项目为 war 包 4.1.1 普通项目打包: 《 1 》选中项目 ---à 点击右键 ---àexport--à 选中 war file-à   《 2 》 Mave 项目导出 war 文件: 选中项目 ---à 点击右键 ---à run as (debug as )-à maven install 4.2.1 解压 tomcat 解压到当前文件夹。后重命名为 tomcat1 和 tomcat2 然后打开 Tomcat 的 conf 目录下的 server.xml ,修改这两个 Tomcat 的启动端口,分别为 8090 和 8100 。 这是 tomcat1 ,我是在默认端口上都加的 10 , tomcat2 在默认端口都加 20

windows 下 ngix + tomcat 集群
windows 下 ngix + tomcat 集群
windows 下 ngix + tomcat 集群

            这样两个 tomcat 就能同时启动

windows 下 ngix + tomcat 集群

        把解压好的项目通常放在和 tomcat 同一级,而不是放在 tomcat webapp 里

windows 下 ngix + tomcat 集群

              在两个 tomcat    conf 文件夹下    server.xml 文件里  找到 139 行    

windows 下 ngix + tomcat 集群

      在下面添加如下语句      路径是你解压好项目的路径

windows 下 ngix + tomcat 集群

  <Context path="" docBase="D:\ruan-jian\tomcat+ning-jiqun\bbs"/>       5.1 整合 nginx+tomcat 5.1.1 配置 nginx 打开 nginx -1.1.14 文件夹 --->conf 文件夹 ---> 打开 nginx.conf 文件 注意下面的配置文件是按照我    目前  tomcat 的端口来进行配置的  也就是   8090    和   8100 ; 如果 改动端口 则需要更改此配置文件;     #user  nobody;# 配置用户或者组,默认为 nobody nobody 。 worker_processes  1;# 允许生成的进程数,默认为 1   #error_log  logs/error.log;# 制定日志路径,级别。这个设置可以放入全局块, http 块, server 块,级别以此为: debug|info|notice|warn|error|crit|alert|emerg #error_log  logs/error.log  notice; #error_log  logs/error.log  info;   #pid        logs/nginx.pid; # 指定 nginx 进程运行文件存放地址     events {     accept_mutex on;   # 设置网路连接序列化,防止惊群现象发生,默认为 on     multi_accept on;  # 设置一个进程是否同时接受多个网络连接,默认为 off     #use epoll;      # 事件驱动模型, select|poll|kqueue|epoll|resig|/dev/poll|eventport     worker_connections  1024;# 最大连接数,默认为 512 }     http {     include       mime.types;# 文件扩展名与文件类型映射表     default_type  application/octet-stream;# 默认文件类型,默认为 text/plain     #access_log off; # 取消服务日志        #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;# 允许 sendfile 方式传输文件,默认为 off ,可以在 http 块, server 块, location 块。     #tcp_nopush     on;       #keepalive_timeout  0;     keepalive_timeout  60; # 连接超时时间,默认为 75s ,可以在 http , server , location 块。       gzip  on;     upstream mysvr { ip_hash;       server 127.0.0.1:8090 weight=1;       server 127.0.0.1:8100 weight=1;     }     server {         listen       89;# 监听端口         server_name  localhost;# 监听地址           #charset koi8-r;           #access_log  logs/host.access.log  main;                    location / {                     proxy_pass  http://mysvr;  # 请求转向 mysvr 定义的服务器列表                  }         #error_page  404              /404.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       8009;     #    listen       somename:8089;     #    server_name  somename  alias  another.alias;       #    location / {     #        root   html;     #        index  index.html index.htm;     #    }     #}         # HTTPS server     #     #server {     #    listen       443 ssl;     #    server_name  localhost;       #    ssl_certificate      cert.pem;     #    ssl_certificate_key  cert.key;       #    ssl_session_cache    shared:SSL:1m;     #    ssl_session_timeout  5m;       #    ssl_ciphers  HIGH:!aNULL:!MD5;     #    ssl_prefer_server_ciphers  on;       #    location / {     #        root   html;     #        index  index.html index.htm;     #    }     #}   } 测试是否成功:启动顺序 先启动 nginx ,之后再启动 tomcat 两者之间的以来关系,所以要按照顺序来开启 Nginx 访问项目路径: http://localhost:89/     5.2.1 如何判断浏览器使用的是哪个服务器? 修改 tomcat 文件夹下 conf 目录下的 server 文件第 105 行

windows 下 ngix + tomcat 集群

    5.3 session 共享问题 在项目的 web.xml 文件最后加上 <distributable/> ,如下图

windows 下 ngix + tomcat 集群