我已经在铁轨上研究红宝石了一个多月。我已经将应用程序部署到生产VPS上,并且对Ruby/Rails一般都感到满意。我现在正在尝试在最新的Rails版本之一中学习和构建应用程序。由于Ruby/Rails的多个版本是Rails开发人员中的常见概念,因此我认为我应该在不同版本中进行编码并在生产环境中维护这些应用程序。
从我的Google和Stackoverflow搜索中,我想做的事情并不常见。但是,它构成了我想做/学习服务器上的轨道和乘客/apache(基于上述目标(的基础。也就是说,在同一域名下托管多个导轨应用程序,有些是相同的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>
甚至还没有尝试为第三应用程序执行虚拟主机文件。我假设客运场会告诉乘客使用正确的/不同的红宝石解释器。但是,我再也找不到任何这样做的人,尤其是找不到有关正在做的事情的解释。当我发现甚至遥远的东西时,它是从6年前开始的,而代码已经过时了,因为据说乘客现在很容易处理这个问题(但是示例在哪里?!(。
似乎当我访问mywebsite.com/profile时,主站点应用程序仍在处理路线,因为它将登录到main_site_path/log/log/production.log(不是第二个应用程序的日志(。
任何帮助都将不胜感激,但是由于我知道我应该具体,这是一些特定的事情,它可能会帮助我知道吗?:当我进行乘客 - 内存stats或主要的应用程序时,每个应用程序是否应该为每个应用程序运行一个乘客流程吗?
我如何正确定义我的主要域中的/配置文件,应通过不同的导轨应用(如果适用,则不同的VirtualHost(?
谢谢。
zomg它可以工作!非常感谢Tadman建议我将NGINX用作反向代理服务器。也就是说,一个NGINX为每个应用程序提供单独的Apache进程。我可以转到mywebsite.com并获取主应用程序。我访问mywebsite.com/subapp并获取第二个应用程序(与主版本相同的Ruby/Rails版本(。我可以转到mywebsite.com/mea并获得第三个应用程序(它的红宝石和栏杆版本与前两个应用不同!(。
部分是可能的,因为Nginx和Apache都有一个可以安装的乘客组件,可以为您提供各种指令,可以用来指定每个URL应该使用哪种应用程序(Passenger_Ruby,让您告诉Nginx whe ruby whe 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