繁体   English   中英

多租户铁路轨道多个应用程序不同版本同一域

[英]Multitenancy Passenger Rails Multiple Apps Different Versions Same Domain

我已经学习Ruby on Rails仅仅一个多月了。 我已经将一个应用程序部署到了生产VPS,并且通常对Ruby / Rails感到满意。 我现在正尝试在一种最新的Rails版本中学习和构建应用程序。 由于Ruby / Rails的多个版本在Rails开发人员中很普遍,我认为我应该尝试使用不同版本的代码并在生产环境中维护这些应用程序。

从我的谷歌搜索和stackoverflow搜索看来,我尝试执行的操作并不常见。 但是,它构成了我想在服务器上进行的所有关于Rails和Passenger / Apache的学习/学习的基础(基于上述目标)。 也就是说,在同一个域名下托管多个Rails应用程序,其中一些是相同的ruby / rails版本,而另一些是不同的版本。 所以:

mywebsite.com <--- Ruby 2.3.4 / Rails 4.2.5

mywebsite.com/profile <---一个单独的应用程序:Ruby 2.3.4 / Rails 4.2.5

mywebsite.com/cool-app <---使用最新和最强大功能的独立应用程序:Ruby 2.5.0 / Rails 5.1.4

当我在stackoverflow中搜索“多租户导轨乘客”时,恰好有0个结果。 也有此链接: https : //www.phusionpassenger.com/library/deploy/apache/

其中有一篇名为“在一台服务器上部署多个应用程序(多租户)”的文章,但尚不存在,并说:“待办事项”! 我一直在尝试迷失方向,但是似乎我不了解太多,仅复制和粘贴别人的代码并使之正常工作。

使这些东西正常工作的技巧之一似乎是使用不同的VirtualHost设置。

这是我为上述应用程序所尝试的:

mywebsite.com(主站点):

<VirtualHost *:80>
  ServerName mywebsite.com

  # Tell Apache and Passenger where your app's 'public' directory is
  DocumentRoot /var/www/login_app/code/public

  PassengerRuby /usr/local/rvm/gems/ruby-2.3.4/wrappers/ruby

  # Relax Apache security settings
  <Directory /var/www/login_app/code/public>
    Allow from all
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    Require all granted
  </Directory>

  <Directory /var/www/login_app/code/public/profile>
    Allow from all
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    Require all granted
  </Directory>

  PassengerBaseURI /profile

</VirtualHost>

mywebsite.com/profile(与主站点相同的Ruby / Rails版本)

<VirtualHost *:80>
  ServerName mywebsite.com

  # Tell Apache and Passenger where your app's 'public' directory is
  DocumentRoot /var/www/test_app/code/public

  PassengerAppRoot /var/www/test_app/code
  PassengerRuby /usr/local/rvm/gems/ruby-2.3.4/wrappers/ruby
  # PassengerBaseURI /profile

  # Relax Apache security settings
  <Directory /var/www/test_app/code/public>
    PassengerEnabled on
    Allow from all
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    Require all granted
  </Directory>
</VirtualHost>

甚至没有尝试为第3个应用程序创建VirtualHost文件。 我假设PassengerRuby字段将告诉Passenger使用正确/不同的Ruby解释器。 但同样,我找不到执行此操作的任何人,尤其是找不到正在执行的操作的任何解释。 当我发现距离最近很近的东西时,那是6年前的代码了,因为乘客现在应该可以轻松地处理此代码了(但是示例在哪里?!)。

好像当我转到mywebsite.com/profile时,主站点应用仍在处理路由,因为它记录到main_site_path / log / production.log(而不是第二个应用的日志)中。

任何帮助将不胜感激,但是由于我知道我应该具体,所以可能有一些我可以帮助我了解的具体事情?:当我执行乘客内存统计信息时,应该为每个应用程序运行一个“乘客”进程吗?主要的?
如何正确定义主域外的/ profile应该由其他Rails应用程序处理(如果适用,则使用不同的VirtualHost)?

谢谢。

ZOMG有效! 非常感谢tadman建议我将Nginx用作反向代理服务器。 也就是说,一个Nginx为每个应用程序提供单独的Apache进程。 我可以转到mywebsite.com并获取主应用程序。 我转到mywebsite.com/subapp并获得第二个应用程序(与主要版本相同的Ruby / Rails版本)。 我可以转到mywebsite.com/mea并获得第三个应用程序(与前两个版本具有不同的Ruby和Rails版本!)。

之所以可行,部分原因是因为NginxApache都可以安装一个Passenger组件,从而为您提供了各种指令,可用于指定每个网址应提供哪种应用程序(passenger_ruby可让您告诉Nginx使用哪个ruby解释器)。 我从未见过像Phusion网站上的文档那样全面和美观。

弄清楚这一点很有趣。 这是我的设置,以便您可以看到我的工作。 并且,如果有什么我可以做得更好的,请告诉我。

Nginx配置:/ etc / nginx / sites-enabled / apache

server {
    listen 80;
    server_name mywebsite.com www.mywebsite.com;

    passenger_enabled on;

    location / {
        passenger_ruby /usr/local/rvm/gems/ruby-2.3.4/wrappers/ruby;
        proxy_pass http://my_website_ip:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /subapp {
        passenger_ruby /usr/local/rvm/gems/ruby-2.3.4/wrappers/ruby;
        proxy_pass http://my_website_ip:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /mea {
        passenger_ruby /usr/local/rvm/gems/ruby-2.5.0/wrappers/ruby;
        proxy_pass http://my_website_ip:8082;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

我的端口文件侦听Nginx服务的端口:

/etc/apache2/ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 8080
Listen 8081
Listen 8082

<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

我的Apache VirtualHost定义。

/etc/apache2/sites-enabled/login_app.conf

<VirtualHost *:8080>
  ServerName mywebsite.com

  # Tell Apache and Passenger where your app's 'public' directory is
  DocumentRoot /var/www/login_app/code/public

  PassengerRuby /usr/local/rvm/gems/ruby-2.3.4/wrappers/ruby

  # Relax Apache security settings
  <Directory /var/www/login_app/code/public>
    Allow from all
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    Require all granted
  </Directory>

</VirtualHost>

<VirtualHost *:8081>
  ServerName mywebsite.com

  # Tell Apache and Passenger where your app's 'public' directory is
  DocumentRoot /var/www/second_app/code/public

  PassengerRuby /usr/local/rvm/gems/ruby-2.3.4/wrappers/ruby

  # Adding a subapp to the base url
  Alias /subapp /var/www/second_app/code/public
  <Location /subapp>
      PassengerBaseURI /subapp
      PassengerAppRoot /var/www/second_app/code
  </Location>

  # Relax Apache security settings
  <Directory /var/www/second_app/code/public>
    Allow from all
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    Require all granted
  </Directory>
</VirtualHost>

<VirtualHost *:8082>
  ServerName mywebsite.com

  # Tell Apache and Passenger where your app's 'public' directory is
  DocumentRoot /var/www/third_app/code/public

  PassengerRuby /usr/local/rvm/gems/ruby-2.5.0/wrappers/ruby

  # Adding a subapp to the base url
  Alias /mea /var/www/third_app/code/public
  <Location /mea>
      PassengerBaseURI /mea
      PassengerAppRoot /var/www/third_app/code
  </Location>

  # Relax Apache security settings
  <Directory /var/www/third_app/code/public>
    Allow from all
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    Require all granted
  </Directory>
</VirtualHost>

并从命令行产生了以下过程: passenger-memory-stats

Version: 5.2.0
Date   : 2018-02-09 03:22:39 +0000

--------- Apache processes ----------
PID    PPID  VMSize    Private  Name
-------------------------------------
             148.9 MB  0.4 MB   /usr/sbin/apache2 -k start
             813.3 MB  3.1 MB   /usr/sbin/apache2 -k start
             557.3 MB  3.2 MB   /usr/sbin/apache2 -k start
### Processes: 3
### Total private dirty RSS: 6.74 MB


---------- Nginx processes -----------
PID    PPID   VMSize    Private  Name
--------------------------------------
              174.8 MB  0.7 MB   nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
              174.8 MB  0.8 MB   nginx: worker process
### Processes: 2
### Total private dirty RSS: 1.57 MB


----- Passenger processes -----
PID    VMSize    Private  Name
-------------------------------
       379.5 MB  4.7 MB   Passenger watchdog
       666.2 MB  7.1 MB   Passenger core
       378.9 MB  4.2 MB   Passenger watchdog
       662.5 MB  5.5 MB   Passenger core
       318.0 MB  63.0 MB  Passenger RubyApp: /var/www/login_app/code (production)
       314.5 MB  60.3 MB  Passenger RubyApp: /var/www/third_app/code (production)
       315.7 MB  61.4 MB  Passenger RubyApp: /var/www/second_app/code (production)
### Processes: 7
### Total private dirty RSS: 206.14 MB

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM