Reputation: 1042
In PHP I could have single php-fpm instance to serve multiple sites. The nginx config I had was looking like so:
upstream backend
{
server 127.0.0.1:9000;
}
# site 1
server
{
server_name www.site1.com;
root /var/www/site1;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass backend;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
# site 2
server
{
server_name www.site2.com;
root /var/www/site2;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass backend; # still the same backend
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
What I see in Ruby world is that for each application a separate independent server is started which listens on a specific port and can can handle requests only to this application. So I'm wondering, is it possible to have the same approach with Ruby applications as I could have with PHP above.
I understand that this could be not very good idea for high-traffic sites, but I'm actually dealing with quite low-traffic sites and my VPS has limited RAM.
Upvotes: 0
Views: 348
Reputation: 42899
yea it's possible with fpm, go to /etc/php5/fpm/pool.d
, you'll find www.conf
, copy it to a new file, say site2.conf
, then you need to change 2 things, first the pool name, you'll find it between [name]
, and then the listen
command, you'll find it on 9000, change it to 9001 for example, or you could do a sock file, I usually prefer that method, then save the file and restart the service, and that's it, I also recommend that you look at the rest of the file, it has quite some interesting features.
I personally used this config for a while on my VPS, multiple pools has few benefits, I configured a pool for each domain/subdomain/website, each could have it's config, like the runner user name ( spared me the permissions issue for log and cache files being owned by www or php or something ) and also according to the traffic you can configure each to have how many waiting childs to serve, initial number of childs and max number, also for me it was easy to see which site is eating resources in top
because i would look at the owner user of the process.
Upvotes: 0
Reputation: 117615
I'm afraid not. Rails' runtime model is a bit different from php. With php, everything is loaded and executed, then dropped again. Nothing shared between each request. This means that the same process can serve requests from completely different applications. In a Rails (or Sinatra) setup, there is an application process running, which responds to requests. This process is comparatively heavy to boot up, so it isn't feasible to setup and tear down for each request. The result is that you need to accept that these processes hang on to system resources even when they aren't working.
Upvotes: 1