Nginx+Tomcat簡單集群


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. }





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM