簡體   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