1.软件准备

下载Nginx和Tomcat

Nginx:http://nginx.org/en/download.html 这里需要下载稳定版:Stable version

Tomcat:下载就不说了,这里使用apache-tomcat-6.0.14版本

解压到一个目录

2.修改Tomcat的端口

Tomcat1:修改Server.xml

D:\nginx_cluster\apache-tomcat-6.0.14_1\conf\server.xml

共修改3处内容:将以下端口都加1

  1. <!--第1处-->
  2. <Server port="18005" shutdown="SHUTDOWN">
  3. <!--第2处-->
  4. <Connector port="18080" protocol="HTTP/1.1"
  5. connectionTimeout="20000"
  6. redirectPort="8443" />
  7. <!--第3处-->
  8. <Connector port="18009" protocol="AJP/1.3" redirectPort="8443" />

Tomcat2:修改Server.xml

D:\nginx_cluster\apache-tomcat-6.0.14_2\conf\server.xml

共修改3处内容:将以下端口都加2

  1. <!--第1处-->
  2. <Server port="28005" shutdown="SHUTDOWN">
  3. <!--第2处-->
  4. <Connector port="28080" protocol="HTTP/1.1"
  5. connectionTimeout="20000"
  6. redirectPort="8443" />
  7. <!--第3处-->
  8. <Connector port="28009" protocol="AJP/1.3" redirectPort="8443" />

3.测试Tomcat是否正常运行

分别访问两个Tomcat

http://localhost:18080/

http://localhost:28080/

都出现猫的页面说明正常,为了区分不同的Tomcat,这里修改${Tmocat_home}\webapps\ROOT\ index.html文件内容,加入内容以便区分

  1. <h1>This Tomcat1</h1>

之后再次访问两个Tomcat





至此,两个Tomcat运行正常。

4.配置Nginx

修改Nginx的主配置文件:

D:\nginx_cluster\nginx-1.10.2\conf\ nginx.conf

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. #监听localhost的80端口
  23. server {
  24. listen 80;
  25. server_name localhost;
  26. location / {
  27. proxy_connect_timeout 3;
  28. proxy_send_timeout 30;
  29. proxy_read_timeout 30;
  30. proxy_pass http://localhost;
  31. }
  32. }
  33. # another virtual host using mix of IP-, name-, and port-based configuration
  34. #
  35. #server {
  36. # listen 8000;
  37. # listen somename:8080;
  38. # server_name somename alias another.alias;
  39. # location / {
  40. # root html;
  41. # index index.html index.htm;
  42. # }
  43. #}
  44. #集群配置:服务器列表
  45. upstream localhost {
  46. server localhost:18080 weight=2;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
  47. server localhost:28080 weight=1;
  48. }
  49. # HTTPS server
  50. #
  51. #server {
  52. # listen 443 ssl;
  53. # server_name localhost;
  54. # ssl_certificate cert.pem;
  55. # ssl_certificate_key cert.key;
  56. # ssl_session_cache shared:SSL:1m;
  57. # ssl_session_timeout 5m;
  58. # ssl_ciphers HIGH:!aNULL:!MD5;
  59. # ssl_prefer_server_ciphers on;
  60. # location / {
  61. # root html;
  62. # index index.html index.htm;
  63. # }
  64. #}
  65. }

主要配置





至此,Nginx的简单配置就完成了。下面开始测试

5.测试集群访问

启动Nginx

进入到Nginx目录

启动命令为:start nginx

停止命令为:nginx –s stop

访问测试

访问:http://localhost/

Nginx内部配置了监听80端口,默认进行服务器的分发。





随便刷新测试了10次,共访问了Tomcat1共8次,Tomcat2共2次。可以看到权重越大,访问到的概率越大。

6.配置文件

Tomcat1 的Server.xml配置文件

  1. <!-- Note: A "Server" is not itself a "Container", so you may not
  2. define subcomponents such as "Valves" at this level.
  3. Documentation at /docs/config/server.html
  4. -->
  5. <Server port="18005" shutdown="SHUTDOWN">
  6. <!--APR library loader. Documentation at /docs/apr.html -->
  7. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  8. <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  9. <Listener className="org.apache.catalina.core.JasperListener" />
  10. <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  11. <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  12. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  13. <!-- Global JNDI resources
  14. Documentation at /docs/jndi-resources-howto.html
  15. -->
  16. <GlobalNamingResources>
  17. <!-- Editable user database that can also be used by
  18. UserDatabaseRealm to authenticate users
  19. -->
  20. <Resource name="UserDatabase" auth="Container"
  21. type="org.apache.catalina.UserDatabase"
  22. description="User database that can be updated and saved"
  23. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  24. pathname="conf/tomcat-users.xml" />
  25. </GlobalNamingResources>
  26. <!-- A "Service" is a collection of one or more "Connectors" that share
  27. a single "Container" Note: A "Service" is not itself a "Container",
  28. so you may not define subcomponents such as "Valves" at this level.
  29. Documentation at /docs/config/service.html
  30. -->
  31. <Service name="Catalina">
  32. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  33. <!--
  34. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  35. maxThreads="150" minSpareThreads="4"/>
  36. -->
  37. <!-- A "Connector" represents an endpoint by which requests are received
  38. and responses are returned. Documentation at :
  39. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  40. Java AJP Connector: /docs/config/ajp.html
  41. APR (HTTP/AJP) Connector: /docs/apr.html
  42. Define a non-SSL HTTP/1.1 Connector on port 8080
  43. -->
  44. <Connector port="18080" protocol="HTTP/1.1"
  45. connectionTimeout="20000"
  46. redirectPort="8443" />
  47. <!-- A "Connector" using the shared thread pool-->
  48. <!--
  49. <Connector executor="tomcatThreadPool"
  50. port="8080" protocol="HTTP/1.1"
  51. connectionTimeout="20000"
  52. redirectPort="8443" />
  53. -->
  54. <!-- Define a SSL HTTP/1.1 Connector on port 8443
  55. This connector uses the JSSE configuration, when using APR, the
  56. connector should be using the OpenSSL style configuration
  57. described in the APR documentation -->
  58. <!--
  59. <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
  60. maxThreads="150" scheme="https" secure="true"
  61. clientAuth="false" sslProtocol="TLS" />
  62. -->
  63. <!-- Define an AJP 1.3 Connector on port 8009 -->
  64. <Connector port="18009" protocol="AJP/1.3" redirectPort="8443" />
  65. <!-- An Engine represents the entry point (within Catalina) that processes
  66. every request. The Engine implementation for Tomcat stand alone
  67. analyzes the HTTP headers included with the request, and passes them
  68. on to the appropriate Host (virtual host).
  69. Documentation at /docs/config/engine.html -->
  70. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  71. <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
  72. -->
  73. <Engine name="Catalina" defaultHost="localhost">
  74. <!--For clustering, please take a look at documentation at:
  75. /docs/cluster-howto.html (simple how to)
  76. /docs/config/cluster.html (reference documentation) -->
  77. <!--
  78. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  79. -->
  80. <!-- The request dumper valve dumps useful debugging information about
  81. the request and response data received and sent by Tomcat.
  82. Documentation at: /docs/config/valve.html -->
  83. <!--
  84. <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
  85. -->
  86. <!-- This Realm uses the UserDatabase configured in the global JNDI
  87. resources under the key "UserDatabase". Any edits
  88. that are performed against this UserDatabase are immediately
  89. available for use by the Realm. -->
  90. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  91. resourceName="UserDatabase"/>
  92. <!-- Define the default virtual host
  93. Note: XML Schema validation will not work with Xerces 2.2.
  94. -->
  95. <Host name="localhost" appBase="webapps"
  96. unpackWARs="true" autoDeploy="true"
  97. xmlValidation="false" xmlNamespaceAware="false">
  98. <!-- SingleSignOn valve, share authentication between web applications
  99. Documentation at: /docs/config/valve.html -->
  100. <!--
  101. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  102. -->
  103. <!-- Access log processes all example.
  104. Documentation at: /docs/config/valve.html -->
  105. <!--
  106. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  107. prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
  108. -->
  109. </Host>
  110. </Engine>
  111. </Service>
  112. </Server>

Tomcat2 的Server.xml配置文件

  1. <!-- Note: A "Server" is not itself a "Container", so you may not
  2. define subcomponents such as "Valves" at this level.
  3. Documentation at /docs/config/server.html
  4. -->
  5. <Server port="28005" shutdown="SHUTDOWN">
  6. <!--APR library loader. Documentation at /docs/apr.html -->
  7. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  8. <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  9. <Listener className="org.apache.catalina.core.JasperListener" />
  10. <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  11. <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  12. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  13. <!-- Global JNDI resources
  14. Documentation at /docs/jndi-resources-howto.html
  15. -->
  16. <GlobalNamingResources>
  17. <!-- Editable user database that can also be used by
  18. UserDatabaseRealm to authenticate users
  19. -->
  20. <Resource name="UserDatabase" auth="Container"
  21. type="org.apache.catalina.UserDatabase"
  22. description="User database that can be updated and saved"
  23. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  24. pathname="conf/tomcat-users.xml" />
  25. </GlobalNamingResources>
  26. <!-- A "Service" is a collection of one or more "Connectors" that share
  27. a single "Container" Note: A "Service" is not itself a "Container",
  28. so you may not define subcomponents such as "Valves" at this level.
  29. Documentation at /docs/config/service.html
  30. -->
  31. <Service name="Catalina">
  32. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  33. <!--
  34. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  35. maxThreads="150" minSpareThreads="4"/>
  36. -->
  37. <!-- A "Connector" represents an endpoint by which requests are received
  38. and responses are returned. Documentation at :
  39. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  40. Java AJP Connector: /docs/config/ajp.html
  41. APR (HTTP/AJP) Connector: /docs/apr.html
  42. Define a non-SSL HTTP/1.1 Connector on port 8080
  43. -->
  44. <Connector port="28080" protocol="HTTP/1.1"
  45. connectionTimeout="20000"
  46. redirectPort="8443" />
  47. <!-- A "Connector" using the shared thread pool-->
  48. <!--
  49. <Connector executor="tomcatThreadPool"
  50. port="8080" protocol="HTTP/1.1"
  51. connectionTimeout="20000"
  52. redirectPort="8443" />
  53. -->
  54. <!-- Define a SSL HTTP/1.1 Connector on port 8443
  55. This connector uses the JSSE configuration, when using APR, the
  56. connector should be using the OpenSSL style configuration
  57. described in the APR documentation -->
  58. <!--
  59. <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
  60. maxThreads="150" scheme="https" secure="true"
  61. clientAuth="false" sslProtocol="TLS" />
  62. -->
  63. <!-- Define an AJP 1.3 Connector on port 8009 -->
  64. <Connector port="28009" protocol="AJP/1.3" redirectPort="8443" />
  65. <!-- An Engine represents the entry point (within Catalina) that processes
  66. every request. The Engine implementation for Tomcat stand alone
  67. analyzes the HTTP headers included with the request, and passes them
  68. on to the appropriate Host (virtual host).
  69. Documentation at /docs/config/engine.html -->
  70. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  71. <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
  72. -->
  73. <Engine name="Catalina" defaultHost="localhost">
  74. <!--For clustering, please take a look at documentation at:
  75. /docs/cluster-howto.html (simple how to)
  76. /docs/config/cluster.html (reference documentation) -->
  77. <!--
  78. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  79. -->
  80. <!-- The request dumper valve dumps useful debugging information about
  81. the request and response data received and sent by Tomcat.
  82. Documentation at: /docs/config/valve.html -->
  83. <!--
  84. <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
  85. -->
  86. <!-- This Realm uses the UserDatabase configured in the global JNDI
  87. resources under the key "UserDatabase". Any edits
  88. that are performed against this UserDatabase are immediately
  89. available for use by the Realm. -->
  90. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  91. resourceName="UserDatabase"/>
  92. <!-- Define the default virtual host
  93. Note: XML Schema validation will not work with Xerces 2.2.
  94. -->
  95. <Host name="localhost" appBase="webapps"
  96. unpackWARs="true" autoDeploy="true"
  97. xmlValidation="false" xmlNamespaceAware="false">
  98. <!-- SingleSignOn valve, share authentication between web applications
  99. Documentation at: /docs/config/valve.html -->
  100. <!--
  101. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  102. -->
  103. <!-- Access log processes all example.
  104. Documentation at: /docs/config/valve.html -->
  105. <!--
  106. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  107. prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
  108. -->
  109. </Host>
  110. </Engine>
  111. </Service>
  112. </Server>

Nginx配置文件

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. #监听localhost的80端口
  23. server {
  24. listen 80;
  25. server_name localhost;
  26. location / {
  27. proxy_connect_timeout 3;
  28. proxy_send_timeout 30;
  29. proxy_read_timeout 30;
  30. proxy_pass http://localhost;
  31. }
  32. }
  33. # another virtual host using mix of IP-, name-, and port-based configuration
  34. #
  35. #server {
  36. # listen 8000;
  37. # listen somename:8080;
  38. # server_name somename alias another.alias;
  39. # location / {
  40. # root html;
  41. # index index.html index.htm;
  42. # }
  43. #}
  44. #集群配置:服务器列表
  45. upstream localhost {
  46. server localhost:18080 weight=2;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
  47. server localhost:28080 weight=1;
  48. }
  49. # HTTPS server
  50. #
  51. #server {
  52. # listen 443 ssl;
  53. # server_name localhost;
  54. # ssl_certificate cert.pem;
  55. # ssl_certificate_key cert.key;
  56. # ssl_session_cache shared:SSL:1m;
  57. # ssl_session_timeout 5m;
  58. # ssl_ciphers HIGH:!aNULL:!MD5;
  59. # ssl_prefer_server_ciphers on;
  60. # location / {
  61. # root html;
  62. # index index.html index.htm;
  63. # }
  64. #}
  65. }

附录:

参考文档

http://www.nginx.cn/doc/index.html

http://tengine.taobao.org/nginx_docs/cn/docs/

http://manual.51yip.com/nginx/

(总结)Nginx配置文件nginx.conf中文详解

  1. #定义Nginx运行的用户和用户组
  2. user www www;
  3. #nginx进程数,建议设置为等于CPU总核心数。
  4. worker_processes 8;
  5. #全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]
  6. error_log /var/log/nginx/error.log info;
  7. #进程文件
  8. pid /var/run/nginx.pid;
  9. #一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。
  10. worker_rlimit_nofile 65535;
  11. #工作模式与连接数上限
  12. events
  13. {
  14. #参考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型是Linux 2.6以上版本内核中的高性能网络I/O模型,如果跑在FreeBSD上面,就用kqueue模型。
  15. use epoll;
  16. #单个进程最大连接数(最大连接数=连接数*进程数)
  17. worker_connections 65535;
  18. }
  19. #设定http服务器
  20. http
  21. {
  22. include mime.types; #文件扩展名与文件类型映射表
  23. default_type application/octet-stream; #默认文件类型
  24. #charset utf-8; #默认编码
  25. server_names_hash_bucket_size 128; #服务器名字的hash表大小
  26. client_header_buffer_size 32k; #上传文件大小限制
  27. large_client_header_buffers 4 64k; #设定请求缓
  28. client_max_body_size 8m; #设定请求缓
  29. sendfile on; #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
  30. autoindex on; #开启目录列表访问,合适下载服务器,默认关闭。
  31. tcp_nopush on; #防止网络阻塞
  32. tcp_nodelay on; #防止网络阻塞
  33. keepalive_timeout 120; #长连接超时时间,单位是秒
  34. #FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。
  35. fastcgi_connect_timeout 300;
  36. fastcgi_send_timeout 300;
  37. fastcgi_read_timeout 300;
  38. fastcgi_buffer_size 64k;
  39. fastcgi_buffers 4 64k;
  40. fastcgi_busy_buffers_size 128k;
  41. fastcgi_temp_file_write_size 128k;
  42. #gzip模块设置
  43. gzip on; #开启gzip压缩输出
  44. gzip_min_length 1k; #最小压缩文件大小
  45. gzip_buffers 4 16k; #压缩缓冲区
  46. gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
  47. gzip_comp_level 2; #压缩等级
  48. gzip_types text/plain application/x-javascript text/css application/xml;
  49. #压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
  50. gzip_vary on;
  51. #limit_zone crawler $binary_remote_addr 10m; #开启限制IP连接数的时候需要使用
  52. upstream blog.ha97.com {
  53. #upstream的负载均衡,weight是权重,可以根据机器配置定义权重。weigth参数表示权值,权值越高被分配到的几率越大。
  54. server 192.168.80.121:80 weight=3;
  55. server 192.168.80.122:80 weight=2;
  56. server 192.168.80.123:80 weight=3;
  57. }
  58. #虚拟主机的配置
  59. server {
  60. #监听端口
  61. listen 80;
  62. #域名可以有多个,用空格隔开
  63. server_name www.ha97.com ha97.com;
  64. index index.html index.htm index.php;
  65. root /data/www/ha97;
  66. location ~ .*\.(php|php5)?$
  67. {
  68. fastcgi_pass 127.0.0.1:9000;
  69. fastcgi_index index.php;
  70. include fastcgi.conf;
  71. }
  72. #图片缓存时间设置
  73. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  74. {
  75. expires 10d;
  76. }
  77. #JS和CSS缓存时间设置
  78. location ~ .*\.(js|css)?$
  79. {
  80. expires 1h;
  81. }
  82. #日志格式设定
  83. log_format access '$remote_addr - $remote_user [$time_local] "$request" '
  84. '$status $body_bytes_sent "$http_referer" '
  85. '"$http_user_agent" $http_x_forwarded_for';
  86. #定义本虚拟主机的访问日志
  87. access_log /var/log/nginx/ha97access.log access;
  88. #对 "/" 启用反向代理
  89. location / {
  90. proxy_pass http://127.0.0.1:88;
  91. proxy_redirect off;
  92. proxy_set_header X-Real-IP $remote_addr;
  93. #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
  94. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  95. #以下是一些反向代理的配置,可选。
  96. proxy_set_header Host $host;
  97. client_max_body_size 10m; #允许客户端请求的最大单文件字节数
  98. client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,
  99. proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间(代理连接超时)
  100. proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时)
  101. proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)
  102. proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
  103. proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的设置
  104. proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
  105. proxy_temp_file_write_size 64k;
  106. #设定缓存文件夹大小,大于这个值,将从upstream服务器传
  107. }
  108. #设定查看Nginx状态的地址
  109. location /NginxStatus {
  110. stub_status on;
  111. access_log on;
  112. auth_basic "NginxStatus";
  113. auth_basic_user_file conf/htpasswd;
  114. #htpasswd文件的内容可以用apache提供的htpasswd工具来产生。
  115. }
  116. #本地动静分离反向代理配置
  117. #所有jsp的页面均交由tomcat或resin处理
  118. location ~ .(jsp|jspx|do)?$ {
  119. proxy_set_header Host $host;
  120. proxy_set_header X-Real-IP $remote_addr;
  121. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  122. proxy_pass http://127.0.0.1:8080;
  123. }
  124. #所有静态文件由nginx直接读取不经过tomcat或resin
  125. location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
  126. { expires 15d; }
  127. location ~ .*.(js|css)?$
  128. { expires 1h; }
  129. }
  130. }

Nginx+Tomcat简单集群的更多相关文章

  1. nginx做负载均衡和tomcat简单集群

    Nginx做负载均衡和TOMCAT简单集群                1.下载安装nginx及其依赖包                                               ...

  2. Apache httpd + tomcat 简单集群

    集群其实很简单,我们就来说一下httpd+tomcat集群都要注意哪些部分: 首先使用的东西有 apache-tomcat-8.0.32      下载地址: http://tomcat.apache ...

  3. 图文解说:Nginx+tomcat配置集群负载均衡

    图文解说:Nginx+tomcat配置集群负载均衡 博客分类: appserver nginxTomcatUbuntuLinux网络应用  作者:niumd Blog:http://ari.iteye ...

  4. Nginx+Tomcat+MemCached 集群配置手册

    系统实施文档 Nginx+Tomcat+MemCached 集群配置手册 目    录 第1章   概述 1.1   目标 互联网的快速发展带来了互联网系统的高负载和高可用性, 这要求我们在设计系统架 ...

  5. nginx+tomcat实现集群,redis实现session共享,软连接实现文件共享:http://blog.csdn.net/hua1586981/article/details/78132710

    转载 2017年02月08日 16:52:41 730 相信很多人都听过nginx,这个小巧的东西慢慢地在吞食apache和IIS的份额.那究竟它有什么作用呢?可能很多人未必了解. 说到反向代理,可能 ...

  6. Nginx + Tomcat搭建集群

    一.Tomcat集群带来的好处 1.提高服务的性能,并发能力,以及高可用性 2.提供项目架构的横向扩展能力 二.Tomcat集群实现原理 通过Nginx负载均衡进行请求转发 三.Nginx + Tom ...

  7. 【转】Nginx+Tomcat+Memcached集群Session共享

    cookie是怎样工作的? 例 如,我们创建了一个名字为login的Cookie来包含访问者的信息,创建Cookie时,服务器端的Header如下面所示,这里假设访问者的注册名 是“Michael J ...

  8. Nginx+Tomcat+Memcached 集群

    写过一篇 Apache Httpd+Tomcat 的集群, 现在来看看Nginx+Tomcat+Memcached是怎么集群的. 先看看用的版本和工具: Nginx: nginx-1.8.1 Tomc ...

  9. session服务器Nginx+Tomcat+Memcached集群Session共享

    cookie是怎样工作的? 例如,我们创立了一个名字为login的Cookie来包含访问者的信息,创立Cookie时,服务器端的Header如下面所示,这里假设访问者的注册名是“Michael Jor ...

随机推荐

  1. 利用Ajax和Servlet实现输入框提示功能

    目的和效果:     输入框输入字符串x,匹配后台传入的数据str,如果str中的元素包含字符串x,则提示. 后台代码:                   String x = request.ge ...

  2. 【eclipse】删除工作空间

  3. 微信网页跳转页面常见bug处理

    微信网页跳转页面常见bug处理 1.不要直接用a链接直接跳转 2.url后加上时间戳 function gohome() { window.location.href = "../home/ ...

  4. setSupportActionBar()方法报错

    在Android开发中,使用ToolBar控件替代ActionBar控件,需要在java代码中使用setSupportActionBar()方法,如下: Toolbar toolbar = (Tool ...

  5. 常见dos命令汇总

    常用的内部命令有md.cd.rd.dir.path.copy.type.edit.ren.del.cls.ver.date.time.prompt.常用的外部命令有deltree.format.dis ...

  6. [ios][swift]UIButton

    参考:http://www.hangge.com/blog/cache/detail_529.html

  7. 统计字符串中每个字符出现的次数(Python)

    #统计字符串中每个字符出现的次数 以The quick brown fox jumps over the lazy dog为例 message='The quick brown fox jumps o ...

  8. (转)Attribute在.net编程中的应用

    Attribute在.net编程中的应用(一)Attribute的基本概念 经常有朋友问,Attribute是什么?它有什么用?好像没有这个东东程序也能运行.实际上在.Net中,Attribute是一 ...

  9. angular5 路由传参的几种方式

    此处介绍三种方式 方式一: 问号后面带的参数, 例如:/product?id=1&name=iphone还可以是: [routerLink]="['/books']" [q ...

  10. 如何将新项目添加到github仓库中?只需简单几步~即可实现

    问题描述:新建了一个项目,如何将其设置为git项目?如何关联到github上的仓库? 只需简单几步,但前提是需要已经安装好了git,并且有github账户 本文使用IntelliJ IDEA 其他编辑 ...