Why it is impossible to make RoR + Nginx work without Passenger? After all, the same Php does not require this. But for Django, Gunicorn seems to be required.

We always admins do this, and I did not delve into these issues. Now for the general development decided to read. And faced with these questions.

  • It is possible without Passenger, you just need to raise one of the rack servers at the application level, for example, you can start with Unicorn. - cheops

3 answers 3

PHP requires PHP-FPM. PHP-FPM is a process that hangs constantly and executes PHP scripts, writing the result to the socket from which Nginx reads. Passenger, Webrick, Unicorn, Thin perform the same role. The script itself does not know anything about GET parameters, POST parameters, headers and so on.

  • Short but clear. Thank. - Ivan Kalayanov

Most applications in PHP, in their essence, are built on the principle of "born to die." Those. To process each new request, a new instance of the application must be created.

Even the use of Fast CGI (PHP-FPM) does not remove this limitation. Its main function is to run the PHP interpreter as a daemon, so that it does not need to be initialized every time. The application continues to be initialized every time you need to respond to the request.

What happens in the rails: The application is one large class, which, among other things, implements the Rack-interface . Thanks to this architecture, it can be permanently loaded into memory. The task of backend servers (such as Unicorn or Puma) is to keep this class in its memory, pass request parameters to it and return a response.

In short (and roughly):

  • PHP-FPM immediately creates an interpreter process that executes php scripts when necessary.
  • Unicorn - immediately loads the entire application into memory and sends it requests for processing.

Theoretically, nothing prevents to write a rack interface for an application on PHP and run it through Unicorn. Just as nothing prevents the use of CGI, including Fast, for launching rail applications (by the way, it seems there were FastCGI implementations for Ruby). But you need to understand that:

  • Heavy rails. Downloading the entire application with each request can be superimposed;
  • Most likely, you will have to add a little frame application, so that it works correctly.
  • Great answer. Thank you very much. - Ivan Kalayanov
  • "Theoretically, nothing prevents you from writing a rack interface for a PHP application," but since Rack is for Ruby, you get a redundant bundle from a web server and a Ruby Rack handler that sends the request to the PHP interpreter and gets the result from it. In the end, instead of two links, you get three, so-so idea. And there is FastCGI for Ruby, all of a sudden ... in Rack ! - D-side
  • @ Button, так себе затея agrees. As well as launching rails via CGI. I just wanted to say that there is such an opportunity, but not that it should be used (apparently, it turned out unclearly). At the expense of the junior for PHP, I can only assume that either there are analogues, or it is not necessary at all. - anoam

puma c nginx is normally friendly even with the default configuration. add gem 'puma' to the gemfile, then install

 bundle install 

in nginx we write the simplest config in the / etc / nginx / sites-enabled / default file

 server { listen 80; location /{ proxy_pass http://localhost:3000; } } 

We start nginx and rails

 sudo service nginx start rails s puma 

And it should work.