工作总结-2-Nginx/Tomcat安装配置
?以下是tomcat + nginx 结合实现的动静分离。
?
1:? Tomcat 安装
??????? 从
??????? http://downloads.jboss.org/jbossweb/2.1.9.GA/jboss-web-2.1.9.GA.tar.gz
? ? ??? 下载 jboss-web-2.1.9.GA.tar.gz
2:?? 从
??????? http://downloads.jboss.org/jbossnative//2.0.10.GA/jboss-native-2.0.10-linux2-x64-ssl.tar.gz
??????? 下载? jboss-native
?
3:?? tar -zxvf? jboss-native-2.0.10-linux2-x64-ssl.tar.gz
?
4: ? ? 在 catalina.sh 加入 一下 内容 :
?
? ? ??? JAVA_HOME=/opt/jdk1.6.0_24
?
? ? ?? export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/jboss-web-2.1.9.GA/native" (native 存放路径)
?
?
以上是tomcat(jboss web server ) 安装并加载? native_lib.
?
?5: 安装nginx?
?
?6: 配置 nginx .conf/nginx.conf
???? #运行用户
??? #user? nobody nobody;
??? #启动进程
??? worker_processes? 5;
??? #全局错误日志及PID文件
??? error_log? logs/error.log notice;
??? pid????????? logs/nginx.pid;
?? #工作模式及连接数上限
?? events {
????????????? #工作模式有:select(标准模式),poll(标准模式),kqueue(高效模式,适用FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 and MacOS X),
????????????? #epoll(高效模式,本例用的。适用Linux 2.6+,SuSE 8.2,),/dev/poll(高效模式,适用Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+)
????????????? use epoll;
????????????? worker_connections????? 10000;
? ? ? ? ? ? ? }
?? #设定http服务器,利用它的反向代理功能提供负载均衡支持
?
? http {
? ? ? ? ?? autoindex on;
?????????? autoindex_exact_size off;
?????????? autoindex_localtime on;
?????????? #设定mime类型
?????????? include????? mime.types;
????????? default_type? text/plain;
????????? #设定日志格式
????????? log_format main??????? '$remote_addr - $remote_user [$time_local] '
??????????????????????????????????????????? '"$request" $status $bytes_sent '
??????????????????????????????????????????? '"$http_referer" "$http_user_agent" '
??????????????????????????????????????????? '"$gzip_ratio"';
????????? log_format download??? '$remote_addr - $remote_user [$time_local] '
???????????????????????? '"$request" $status $bytes_sent '
???????????????????????? '"$http_referer" "$http_user_agent" '
???????????????????????? '"$http_range" "$sent_http_content_range"';
? #设定请求缓冲
? client_header_buffer_size??? 10k;
? large_client_header_buffers? 4 4k;
? #开启gzip模块,要求安装gzip 在运行./config时要指定
? gzip on;
? gzip_min_length? 1100;
? gzip_buffers??? 4 8k;
? gzip_types????? text/plain;
? output_buffers? 1 32k;
? postpone_output? 1460;
? #设定访问日志
? access_log? logs/access.log? main;
? client_header_timeout? 3m;
? client_body_timeout??? 3m;
? send_timeout????????? 3m;
? sendfile??????????????? on;
? tcp_nopush????????????? on;
? tcp_nodelay??????????? on;
? keepalive_timeout? 65;
? #设定负载均衡的服务器列表
? upstream route {
? #weigth参数表示权值,权值越高被分配到的几率越大
? #本例是指在同一台服务器,多台服务器改变ip即可
? server localhost:8080;
? #server 127.0.0.1:8082;
? #server 127.0.0.1:8083;
? }
? #设定虚拟主机,默认为监听80端口,改成其他端口会出现问题
? server {
??? listen???????? 80;
??? #server_name??? test.com www.test.com;
??? charset gbk;
??? #设定本虚拟主机的访问日志
?? # access_log? logs/test.com.log? main;
??? location / {
??? #root? /xxxxx/web/;
??? # deny??? all;
?? }
?? location ~(favicon.ico) {
?? log_not_found off;
?? expires 30d;
?? break;
???? }
????
???? location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|html|htm|js|css|png)$ {
???? root? /xxxxx/web/;
???? #expires 30d;
????? }
???? #location ~ ^/apps/.*\.(gif|jpg|jpeg|png|bmp|swf)$ {
???? #root? /xxxxx/web/;
???? #expires 30d;
???? # }
???? location /portal/ {
?????? #proxy_pass??? http://route/;
?????? proxy_pass??? http://localhost:8080/;
? #?? #expires 30d;
??? }
??? location /WeatherPlus/ {
?????? #proxy_pass??? http://route/;
?????? proxy_pass??? http://192.168.12.21:8080/WeatherPlus/;
? #?? #expires 30d;
??? }
?location /dyapps/ {
?????? #proxy_pass??? http://route/;
?????? proxy_pass??? http://localhost:8180/;
? #?? #expires 30d;
??? }
}
}
7: tomcat 配置
???? <Server port="8005" shutdown="SHUTDOWN">
? <!--APR library loader. Documentation at /docs/apr.html -->
? <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
? <!--Initialize Jasper prior to webapps deployment. Documentation at /docs/jasper-howto.html -->
? <Listener className="org.apache.catalina.core.JasperListener" />
? <!-- 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" />
? <!-- 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">
??? <!-- A "Connector" represents an endpoint by which requests are received
???????? and responses are returned. Documentation at :
???????? Java HTTP Connector: /docs/config/http.html
???????? Java AJP? Connector: /docs/config/ajp.html
???????? If APR is installed, additional Connector documentation: /docs/apr.html
???????? Define a non-SSL HTTP/1.1 Connector on port 8080.
???????? For HTTPS, refer to the documentation.
???????? JSSE documentation: /docs/ssl-howto.html
???????? Using APR and OpenSSL: /docs/apr.html
??? -->
??? <Connector port="18080" protocol="HTTP/1.1"
?????????????? connectionTimeout="20000" redirectPort="8443" />
??? <!-- Define an AJP 1.3 Connector on port 8009 -->
??? <Connector port="8009" 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">
????? <!--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"/>
????? -->
????? <Realm className="org.apache.catalina.realm.MemoryRealm"/>
????? <!-- 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>
? <Service name="portal">
??? <Connector port="8080" protocol="HTTP/1.1"?? maxThreads="10240" connectionTimeout="10000"? enableLookups="false"??????? redirectPort="8443" URIEncoding="GBK" />
????? <Engine name="portal" defaultHost="localhost">
?????????? <Host name="localhost"? appBase="/xxxxx/web/portal"??? unpackWARs="true"? autoDeploy="true"?? xmlValidation="false" xmlNamespaceAware="false">
????????????? <!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
????????????????? prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> -->
???????????? </Host>
??? </Engine>
?</Service>
?<Service name="dyapps">
??? <Connector port="8180" protocol="HTTP/1.1"????? maxThreads="10240" connectionTimeout="10000"? enableLookups="false"??? redirectPort="8443" URIEncoding="GBK" />
????? <Engine name="dyapps" defaultHost="localhost">
?????????? <Host name="localhost"? appBase="/xxxxx/web/dyapps"??? unpackWARs="true"? autoDeploy="true"?? xmlValidation="false" xmlNamespaceAware="false">
?????????????? <!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
????????????????? prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> -->
???????????? </Host>
??? </Engine>
?</Service>
</Server>