ruby-on-rails - How Apache interacts with application servers
为情所困
为情所困 2017-05-16 17:03:37
0
3
775

One of the Rails deployment solutions is that Apache acts as a Reverse Proxy and forwards requests to the application server (such as Phusion Passenger). As a reverse proxy server, how does Apache interact with the application server behind it?
For example, my Apache listens to port 1080 and checked the process information:

> ps aux | grep /MyWebsite/bin/httpd
googly    8353  0.0  0.0  73856  3280 ?        Ss   Aug26   0:00 /MyWebsite/bin/httpd -d /MyWebsite -f var/state/apache-1080/httpd.conf
googly    8391  0.0  0.0  73856  1828 ?        S    Aug26   0:00 /MyWebsite/bin/httpd -d /MyWebsite -f var/state/apache-1080/httpd.conf
... # 起了10个进程,并且我知道8353是父进程,其余的是子进程

When a request comes, it will first go to Apache. Apache will allocate a process from these processes to handle the request (for example, the process 8391 is allocated). So what will the process 8391 do? Will he forward this request to the subsequent application server (Phusion Passenger)? If so, does the application server also have its own independent process? Or can the process 8391 be regarded as an application server process, and it can handle this request by itself?
How does Apache interact with the application server hanging behind it?

为情所困
为情所困

reply all(3)
过去多啦不再A梦

I’ve seen this question for a long time and didn’t answer it at the time. Let me answer it now.

Rails comes with its own web server, which is responsible for listening to specific ports to provide services.

Ruby language has http-related APIs, and you can even write a simple static file server yourself. And there are many powerful gems that provide similar services.

Apache is a professional http server. In principle, it can only respond to the most basic static files.

The most common way for PHP language to run under Apache is as its plug-in. In other words, Apache is changed to respond to php file requests.

Using Apache with Phusion Passenger to deploy Rails applications is mainly for more elegant error prompts and automated error handling (mainly restarting), as well as a more complete logging system and advanced functions such as load balancing.

It is also possible to use web servers such as rails s or thin to start services, but it is not that easy to use for both browsers and developers.

If you don’t need automatic error handling, using nginx reverse proxy rails s or thin port is the best choice.

洪涛

If you configure a reverse proxy, Apache will then act as an HTTP client to send the same request to the application server, and then send the result to the real client.

刘奇

After you start apache, it will have more than ten or twenty processes (it depends on your configuration)
Then after apache receives the request, a process will process it. If it meets the conditions of the reverse proxy, the request will be sent to your application server
In fact, the application server should be able to be accessed directly (unless there is a firewall or something)
Anyway, the application server receives the request and then sends a response back to apache
apache then sends the response back to the browser
However, during this process, you may also need to configure the rewriting of the url in the html in the response

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!