大部分的时候都是一个resion跑一个应用,这样很容易管理,一天领导要求跑多个应用,无奈只能google,通过搜到的一些碎片,总算是成功的跑了三个应用,把过程记录下来以备不时之需,如果错误请指正。

环境:

os: ubuntu 11.04 64位


1. 安装jdk,并配置好环境变量:

2. 编译安装resion:

wget http://www.caucho.com/download/resin-3.1.11.tar.gz
  tar -xvf resin-3.1.11.tar.gz
  ./configure
  make && make install

3. 配置应用目录:

mkdir web-app
cd web-app
mkdir app1 app2 app3

并在每个app文件夹下面放置好测试的index文件,直接拷贝nginx的index.html即可,并修改里面的body作为应用的标记,比如"This is app1" ...。


4. 编译安装nginx:

wget http://nginx.org/download/nginx-1.3.10.tar.gz
tar -xvf nginx-1.3.10.tar.gz
ln -s nginx-1.3.10 nginx
cd nginx
./configure
make && make install

   在编译的过程中,可能会遇到各种问题,其实就是缺少相应的依赖包,下面是我遇到的问题:

问题:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解决办法:
sudo apt-get install libpcre3-dev
问题:
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option
解决方法:
sudo apt-get install libssl-dev
问题:
make: *** No rule to make target `build', needed by `default'. Stop.
解决方法:
下载编译安装 pcre
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz
在编译pcre的时候,也可能遇到问题:
configure: error: You need a C++ compiler for C++ support.
解决方法:
sudo apt-get install g++


5. resin的配置文件:


<resin xmlns="http://caucho.com/ns/resin"
       xmlns:resin="http://caucho.com/ns/resin/core">
  <!-- adds all .jar files under the resin/lib directory -->
  <class-loader>
    <tree-loader path="${resin.home}/lib"/>
    <tree-loader path="${resin.root}/lib"/>
  </class-loader>
  <!--
     - Management configuration
    -->
  <management path="${resin.root}/admin">
  </management>
  <!--
     - Logging configuration for the JDK logging API.
    -->
  <log name="" path="stdout:" timestamp="[%H:%M:%S.%s] "/>
  <!--
     - 'info' for production
     - 'fine' or 'finer' for development and troubleshooting
    -->
  <logger name="com.caucho" level="info"/>
  <logger name="com.caucho.java" level="config"/>
  <logger name="com.caucho.loader" level="config"/>
  <!--
     - For production sites, change dependency-check-interval to something
     - like 600s, so it only checks for updates every 10 minutes.
    -->
  <dependency-check-interval>2s</dependency-check-interval>
  <!--
     - SMTP server for sending mail notifications
    -->
  <system-property mail.smtp.host="127.0.0.1"/>
  <system-property mail.smtp.port="25"/>
  <!--
     - You can change the compiler to "javac", "eclipse" or "internal".
    -->
  <javac compiler="internal" args="-source 1.5"/>
<cluster id="app-tier">
    <!-- sets the content root for the cluster, relative to server.root -->
    <root-directory>.</root-directory>
    <resin:import path="${resin.home}/conf/app-default.xml"/>
    <!-- configures a deployment directory for virtual hosts -->
    <host-deploy path="hosts">
      <host-default>
         <access-log path="logs/app1-access.log"
            format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
           rollover-period="1D"/>
        <resin:import path="host.xml" optional="true"/>
      </host-default>
    </host-deploy>
    <server id="app1" port="6801">
      <http id="" port="8081"/>
    </server>
    <host id="" root-directory=".">
    <log name="" level="info" path="log/stdout_app1.log" timestamp="[%H:%M:%S.%s] "
    archive-format="stdout_app1.log.%Y-%m-%d.gz"
     rollover-period="1D"/>
      <web-app id="/app1" root-directory="/home/ubuntu/web-app/app1"/>
      <!--<web-app id="/" root-directory="webapps/dgyb"/>-->
    </host>
                                                            
                                                            
  </cluster>
<cluster id="app-tier2">
    <!-- sets the content root for the cluster, relative to server.root -->
    <root-directory>.</root-directory>
    <resin:import path="${resin.home}/conf/app-default.xml"/>
    <!-- configures a deployment directory for virtual hosts -->
    <host-deploy path="hosts">
      <host-default>
         <access-log path="logs/app2-access.log"
            format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
            rollover-period="1D"/>
        <resin:import path="host.xml" optional="true"/>
      </host-default>
    </host-deploy>
    <server id="app2" port="6802">
      <http id="" port="8082"/>
    </server>
    <host id="" root-directory=".">
    <log name="" level="info" path="log/stdout_app2.log" timestamp="[%H:%M:%S.%s] "
     archive-format="stdout_app2.log.%Y-%m-%d.gz"
     rollover-period="1D"/>
    <log name="com.caucho.java" level="config" path="log/stdout_app2.log"
       timestamp="[%H:%M:%S.%s] "/>
    <log name="com.caucho.loader" level="config" path="log/stdout_app2.log"
       timestamp="[%H:%M:%S.%s] "/>
      <web-app id="/app2" root-directory="/home/ubuntu/web-app/app2"/>
    </host>
  </cluster>
                                                           
  <cluster id="app-tier3">
    <!-- sets the content root for the cluster, relative to server.root -->
    <root-directory>.</root-directory>
    <resin:import path="${resin.home}/conf/app-default.xml"/>
    <!-- configures a deployment directory for virtual hosts -->
    <host-deploy path="hosts">
      <host-default>
         <access-log path="logs/app3-access.log"
            format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
            rollover-period="1D"/>
        <resin:import path="host.xml" optional="true"/>
      </host-default>
    </host-deploy>
    <server id="app3" port="6803">
      <http id="" port="8083"/>
    </server>
    <host id="" root-directory=".">
     <log name="" level="info" path="log/stdout_app3.log" timestamp="[%H:%M:%S.%s] "
     archive-format="stdout_app3.log.%Y-%m-%d.gz"
     rollover-period="1D"/>
      <web-app id="/app3" root-directory="/home/ubuntu/web-app/app3/"/>
    </host>
  </cluster>
</resin>


6. nginx的配置文件:

#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;
   sendfile        on;
   keepalive_timeout  65;
#gzip  on;
   upstream app1 {
      server 127.0.0.1:8081;
   }
   upstream app2 {
          server 127.0.0.1:8082;
   }
   upstream app3 {
                  server 127.0.0.1:8083;
   }
   upstream test {
      server 127.0.0.1:8081;
      server 127.0.0.1:8082;
   }
   server {
      listen       80;
      server_name  54.248.221.116;
#charset koi8-r;
#access_log  logs/host.access.log  main;
#error_page  404              /404.html;
# redirect server error pages to the static page /50x.html
      location /app1 {
         proxy_pass http://app1;
         proxy_set_header X-Real-IP $remote_addr;
      }
      location /app2 {
         proxy_pass http://app2;
         proxy_set_header X-Real-IP $remote_addr;
         index  index.html index.htm;
      }
      location /app3 {
         proxy_pass http://app3;
         proxy_set_header X-Real-IP $remote_addr;
         index  index.html index.htm;
      }
}


7. 启动nginx和resin:

~/resin/bin/httpd.sh -server app1 start
~/resin/bin/httpd.sh -server app2 start
~/resin/bin/httpd.sh -server app3 start
sudo /usr/local/nginx/sbin/nginx &


打开浏览器,访问 xxx.xxxx.xxx.xxx/app1 xxx.xxxx.xxx.xxx/app2 xxx.xxxx.xxx.xxx/app3


大功告成。