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?
I’ve seen this question for a long time and didn’t answer it at the time. Let me answer it now.
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.
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.
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 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