少年阿賓

          那些青春的歲月

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
          //nginx.conf


          #user  nobody;
          worker_processes  1;

          #error_log  logs/error.log;
          #error_log  logs/error.log  notice;
          error_log  logs/error.log  info;

          pid        logs/nginx.pid;


          events {
              worker_connections  1024;
          }


          http {
              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;
              include    gzip.conf; 
              upstream localhost { 
                #根據(jù)ip計(jì)算將請(qǐng)求分配各那個(gè)后端tomcat,許多人誤認(rèn)為可以解決session問(wèn)題,其實(shí)并不能。 
                #同一機(jī)器在多網(wǎng)情況下,路由切換,ip可能不同 
                #ip_hash;  
                server localhost:16300  weight=5; 
                server localhost:16400  weight=1; 
               } 

              server {
                  listen       80;
                  server_name  localhost;

                  #charset koi8-r;

                  #access_log  logs/host.access.log  main;

                  location / {
                proxy_connect_timeout   3; 
                              proxy_send_timeout      30; 
                              proxy_read_timeout      30; 
                              proxy_pass http://localhost
                      root   html;
                      index  index.html index.htm;
                  }

                  #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_HOME%/conf/下面新增proxy.conf
          proxy_redirect          off; 
          proxy_set_header        Host $host; 
          proxy_set_header        X-Real-IP $remote_addr; 
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for; 
          client_max_body_size    10m; 
          client_body_buffer_size 128k; 
          proxy_connect_timeout   300; 
          proxy_send_timeout      300; 
          proxy_read_timeout      300; 
          proxy_buffer_size       4k; 
          proxy_buffers           4 32k; 
          proxy_busy_buffers_size 64k; 
          proxy_temp_file_write_size 64k;




          //在%NGINX_HOME%/conf/下面新增gzip.conf
          gzip              on; 
          gzip_min_length      1000; 
          gzip_types         text/plain text/css application/x-javascript;





          //tomcat63    %TOMCAT_HOME%/conf/server.xml

          <?xml version='1.0' encoding='utf-8'?>
          <!--
            Licensed to the Apache Software Foundation (ASF) under one or more
            contributor license agreements.  See the NOTICE file distributed with
            this work for additional information regarding copyright ownership.
            The ASF licenses this file to You under the Apache License, Version 2.0
            (the "License"); you may not use this file except in compliance with
            the License.  You may obtain a copy of the License at

                http://www.apache.org/licenses/LICENSE-2.0

            Unless required by applicable law or agreed to in writing, software
            distributed under the License is distributed on an "AS IS" BASIS,
            WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            See the License for the specific language governing permissions and
            limitations under the License.
          -->
          <!-- Note:  A "Server" is not itself a "Container", so you may not
               define subcomponents such as "Valves" at this level.
               Documentation at /docs/config/server.html
           -->
          <Server port="16305" shutdown="SHUTDOWN">

            <!--APR library loader. Documentation at /docs/apr.html -->
            <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
            <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
            <Listener className="org.apache.catalina.core.JasperListener" />
            <!-- Prevent memory leaks due to use of particular java/javax APIs-->
            <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
            <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
            <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
            <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

            <!-- Global JNDI resources
                 Documentation at /docs/jndi-resources-howto.html
            -->
            <GlobalNamingResources>
              <!-- Editable user database that can also be used by
                   UserDatabaseRealm to authenticate users
              -->
              <Resource name="UserDatabase" auth="Container"
                        type="org.apache.catalina.UserDatabase"
                        description="User database that can be updated and saved"
                        factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                        pathname="conf/tomcat-users.xml" />
            </GlobalNamingResources>

            <!-- A "Service" is a collection of one or more "Connectors" that share
                 a single "Container" Note:  A "Service" is not itself a "Container",
                 so you may not define subcomponents such as "Valves" at this level.
                 Documentation at /docs/config/service.html
             -->
            <Service name="Catalina">
           
              <!--The connectors can use a shared executor, you can define one or more named thread pools-->
              <!--
              <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
                  maxThreads="150" minSpareThreads="4"/>
              -->
             
             
              <!-- A "Connector" represents an endpoint by which requests are received
                   and responses are returned. Documentation at :
                   Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
                   Java AJP  Connector: /docs/config/ajp.html
                   APR (HTTP/AJP) Connector: /docs/apr.html
                   Define a non-SSL HTTP/1.1 Connector on port 8080
              -->
              <Connector port="16300" protocol="HTTP/1.1"
                         connectionTimeout="20000"
                         redirectPort="8443" />
              <!-- A "Connector" using the shared thread pool-->
              <!--
              <Connector executor="tomcatThreadPool"
                         port="8080" protocol="HTTP/1.1"
                         connectionTimeout="20000"
                         redirectPort="8443" />
              -->          
              <!-- Define a SSL HTTP/1.1 Connector on port 8443
                   This connector uses the JSSE configuration, when using APR, the
                   connector should be using the OpenSSL style configuration
                   described in the APR documentation -->
              <!--
              <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
                         maxThreads="150" scheme="https" secure="true"
                         clientAuth="false" sslProtocol="TLS" />
              -->

              <!-- Define an AJP 1.3 Connector on port 8009 -->
              <Connector port="16309" protocol="AJP/1.3" redirectPort="8443" />


              <!-- An Engine represents the entry point (within Catalina) that processes
                   every request.  The Engine implementation for Tomcat stand alone
                   analyzes the HTTP headers included with the request, and passes them
                   on to the appropriate Host (virtual host).
                   Documentation at /docs/config/engine.html -->

              <!-- You should set jvmRoute to support load-balancing via AJP ie :
              <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">        
              -->
              <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat63">

                <!--For clustering, please take a look at documentation at:
                    /docs/cluster-howto.html  (simple how to)
                    /docs/config/cluster.html (reference documentation) -->
                <!--
                <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
                -->       

                <!-- The request dumper valve dumps useful debugging information about
                     the request and response data received and sent by Tomcat.
                     Documentation at: /docs/config/valve.html -->
                <!--
                <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
                -->

                <!-- This Realm uses the UserDatabase configured in the global JNDI
                     resources under the key "UserDatabase".  Any edits
                     that are performed against this UserDatabase are immediately
                     available for use by the Realm.  -->
                <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                       resourceName="UserDatabase"/>

                <!-- Define the default virtual host
                     Note: XML Schema validation will not work with Xerces 2.2.
                 -->
                <Host name="localhost"  appBase="webapps"
                      unpackWARs="true" autoDeploy="true"
                      xmlValidation="false" xmlNamespaceAware="false">

                  <!-- SingleSignOn valve, share authentication between web applications
                       Documentation at: /docs/config/valve.html -->
                  <!--
                  <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
                  -->

                  <!-- Access log processes all example.
                       Documentation at: /docs/config/valve.html -->
                  <!--
                  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
                         prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
                  -->

                </Host>
              </Engine>
            </Service>
          </Server>




          %TOMCAT_HOME%/conf/server.xml

          <?xml version='1.0' encoding='utf-8'?>
          <!--
            Licensed to the Apache Software Foundation (ASF) under one or more
            contributor license agreements.  See the NOTICE file distributed with
            this work for additional information regarding copyright ownership.
            The ASF licenses this file to You under the Apache License, Version 2.0
            (the "License"); you may not use this file except in compliance with
            the License.  You may obtain a copy of the License at

                http://www.apache.org/licenses/LICENSE-2.0

            Unless required by applicable law or agreed to in writing, software
            distributed under the License is distributed on an "AS IS" BASIS,
            WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            See the License for the specific language governing permissions and
            limitations under the License.
          -->
          <!-- Note:  A "Server" is not itself a "Container", so you may not
               define subcomponents such as "Valves" at this level.
               Documentation at /docs/config/server.html
           -->
          <Server port="16405" shutdown="SHUTDOWN">

            <!--APR library loader. Documentation at /docs/apr.html -->
            <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
            <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
            <Listener className="org.apache.catalina.core.JasperListener" />
            <!-- Prevent memory leaks due to use of particular java/javax APIs-->
            <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
            <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
            <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
            <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

            <!-- Global JNDI resources
                 Documentation at /docs/jndi-resources-howto.html
            -->
            <GlobalNamingResources>
              <!-- Editable user database that can also be used by
                   UserDatabaseRealm to authenticate users
              -->
              <Resource name="UserDatabase" auth="Container"
                        type="org.apache.catalina.UserDatabase"
                        description="User database that can be updated and saved"
                        factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                        pathname="conf/tomcat-users.xml" />
            </GlobalNamingResources>

            <!-- A "Service" is a collection of one or more "Connectors" that share
                 a single "Container" Note:  A "Service" is not itself a "Container",
                 so you may not define subcomponents such as "Valves" at this level.
                 Documentation at /docs/config/service.html
             -->
            <Service name="Catalina">
           
              <!--The connectors can use a shared executor, you can define one or more named thread pools-->
              <!--
              <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
                  maxThreads="150" minSpareThreads="4"/>
              -->
             
             
              <!-- A "Connector" represents an endpoint by which requests are received
                   and responses are returned. Documentation at :
                   Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
                   Java AJP  Connector: /docs/config/ajp.html
                   APR (HTTP/AJP) Connector: /docs/apr.html
                   Define a non-SSL HTTP/1.1 Connector on port 8080
              -->
              <Connector port="16400" protocol="HTTP/1.1"
                         connectionTimeout="20000"
                         redirectPort="8443" />
              <!-- A "Connector" using the shared thread pool-->
              <!--
              <Connector executor="tomcatThreadPool"
                         port="8080" protocol="HTTP/1.1"
                         connectionTimeout="20000"
                         redirectPort="8443" />
              -->          
              <!-- Define a SSL HTTP/1.1 Connector on port 8443
                   This connector uses the JSSE configuration, when using APR, the
                   connector should be using the OpenSSL style configuration
                   described in the APR documentation -->
              <!--
              <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
                         maxThreads="150" scheme="https" secure="true"
                         clientAuth="false" sslProtocol="TLS" />
              -->

              <!-- Define an AJP 1.3 Connector on port 8009 -->
              <Connector port="16409" protocol="AJP/1.3" redirectPort="8443" />


              <!-- An Engine represents the entry point (within Catalina) that processes
                   every request.  The Engine implementation for Tomcat stand alone
                   analyzes the HTTP headers included with the request, and passes them
                   on to the appropriate Host (virtual host).
                   Documentation at /docs/config/engine.html -->

              <!-- You should set jvmRoute to support load-balancing via AJP ie :
              <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">        
              -->
              <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat64">

                <!--For clustering, please take a look at documentation at:
                    /docs/cluster-howto.html  (simple how to)
                    /docs/config/cluster.html (reference documentation) -->
                <!--
                <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
                -->       

                <!-- The request dumper valve dumps useful debugging information about
                     the request and response data received and sent by Tomcat.
                     Documentation at: /docs/config/valve.html -->
                <!--
                <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
                -->

                <!-- This Realm uses the UserDatabase configured in the global JNDI
                     resources under the key "UserDatabase".  Any edits
                     that are performed against this UserDatabase are immediately
                     available for use by the Realm.  -->
                <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                       resourceName="UserDatabase"/>

                <!-- Define the default virtual host
                     Note: XML Schema validation will not work with Xerces 2.2.
                 -->
                <Host name="localhost"  appBase="webapps"
                      unpackWARs="true" autoDeploy="true"
                      xmlValidation="false" xmlNamespaceAware="false">

                  <!-- SingleSignOn valve, share authentication between web applications
                       Documentation at: /docs/config/valve.html -->
                  <!--
                  <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
                  -->

                  <!-- Access log processes all example.
                       Documentation at: /docs/config/valve.html -->
                  <!--
                  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
                         prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
                  -->

                </Host>
              </Engine>
            </Service>
          </Server>





          先啟動(dòng)nginx,后啟動(dòng)tomcat。

          首先測(cè)試nginx配置是否正確,測(cè)試命令:nginx -t  (默認(rèn)驗(yàn)證:conf\nginx.conf),也可以指定配置文件路徑。

          其次驗(yàn)證tomcat,啟動(dòng)兩個(gè)tomcat,不出現(xiàn)端口沖突即為成功(tomcat依賴的java等搞“挨踢”的就廢話不說(shuō)了);


           

          posted on 2013-01-03 14:47 abin 閱讀(619) 評(píng)論(0)  編輯  收藏 所屬分類: nginx

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 罗源县| 二连浩特市| 宜州市| 德钦县| 高阳县| 驻马店市| 安泽县| 马关县| 昂仁县| 抚远县| 通许县| 太白县| 休宁县| 广宁县| 基隆市| 永和县| 邢台县| 东宁县| 灵石县| 洪泽县| 原平市| 乌兰浩特市| 宝丰县| 徐水县| 增城市| 禹州市| 招远市| 民丰县| 夏邑县| 景东| 九龙县| 海门市| 巫溪县| 高邑县| 洛阳市| 博罗县| 九龙县| 赫章县| 固安县| 日照市| 广元市|