LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-13-2018, 08:29 AM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
understanding apache proxy unix sockets with pipe localhost


I was trying to understand how apache could communicate with php-fpm through unix sockets, when I came across this example:
Code:
<FilesMatch \.php$>
    SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost/"
</FilesMatch>
My question is, why is it necessary to pipe the socket into the fcgi://localhost/? How does it work exactly?

Where does apache take the meaning of 'fcgi' from in this context? From proxy_fcgi_module? Or from fastcgi_module? Or both?
 
Old 04-14-2018, 05:47 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by vincix View Post
My question is, why is it necessary to pipe the socket into the fcgi://localhost/? How does it work exactly?
FPM is not "part" of Apache but an external service. The daemon usually listens on a UNIX socket, meaning not exposed to the 'net but confined to localhost and w/o TCP protocol overhead. To be able to hand off jobs to it you must also speak the right protocol and that's FCGI.


Quote:
Originally Posted by vincix View Post
Where does apache take the meaning of 'fcgi' from in this context? From proxy_fcgi_module? Or from fastcgi_module? Or both?
No, fastcgi_module and proxy_fcgi_module are different DSO's: https://wiki.apache.org/httpd/PHP-FPM and https://httpd.apache.org/docs/2.4/mo...roxy_fcgi.html are your friends.
 
Old 04-14-2018, 06:13 AM   #3
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
I loved the phrase "hand off jobs"... really on the nose ) (I know - or I think I know - it wasn't intentional, but still quite funny!)

Well, I kind of already read what you're linking to and other similar resources (not that a reread would hurt). My question is a little bit less naive than it seems to be, or at least that's what I like to believe. In a way it has more to do with the way unix sockets work. If php-fpm uses unix-sockets, isn't it redundant to pipe it into localhost? I mean, could you normally set up a communication session between two apps through unix sockets some other way than on the same localhost? I'm guessing 'localhost' is more related to 'fcgi', meaning that in order to bind the php-fpm unix socket to the fcgi, you simply need to add the fcgi syntax that presupposes specifying localhost - which otherwise would use a tcp socket. Does that make sense?

So apache knows to interpret the special meaning of 'fcgi' using the proxy_fcgi_module, right? But I had used mod_php and fastcgi_module, then it would have used this latter module to interpret it? Or it wouldn't make sense using it in this context?
 
Old 04-14-2018, 06:37 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by vincix View Post
I loved the phrase "hand off jobs"... really on the nose ) (I know - or I think I know - it wasn't intentional, but still quite funny!)
It is as that's exactly how it works: dump a job, hope it timely returns a usable payload.


Quote:
Originally Posted by vincix View Post
If php-fpm uses unix-sockets, isn't it redundant to pipe it into localhost? I mean, could you normally set up a communication session between two apps through unix sockets some other way than on the same localhost? I'm guessing 'localhost' is more related to 'fcgi', meaning that in order to bind the php-fpm unix socket to the fcgi, you simply need to add the fcgi syntax that presupposes specifying localhost - which otherwise would use a tcp socket. Does that make sense?
Yes but we look at it from different angles. Indeed where the socket lives doesn't matter, it could have been "loadbalancer.fpm-pool-3.yourdo.main", but it isn't redundant. (Remove it and see if it still works? ;-p) And "fcgi://" is only related to location in the sense of the "incantation" needed to summon this lesser daemon in its known location: you shan't talk dav:// to it, nor bitcoin:// nor ed2k://, only fcgi://.


Quote:
Originally Posted by vincix View Post
So apache knows to interpret the special meaning of 'fcgi' using the proxy_fcgi_module, right? But I had used mod_php and fastcgi_module, then it would have used this latter module to interpret it?
If you'd use the latter then you'd prolly use a different syntax but it would know how to interpret things, yes.
 
  


Reply

Tags
apache2, php-fpm, proxy_fcgi, socket



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mail received at sendmail has relay=localhost [[UNIX: localhost]] check_rcpt fails chingupt Linux - Distributions 3 04-25-2013 05:36 PM
Understanding popen(), pipe(), etc. MTK358 Linux - General 2 06-25-2011 12:23 PM
Program to forward tcp sockets to unix domain sockets mikepol Linux - Networking 0 09-27-2007 09:49 AM
Sockets, pthread, pipe, and fork -- a messaging server ggravarr Programming 3 06-28-2005 02:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration