using php-fpm with apache AND nginx

merlinsilk

Verified User
Joined
Feb 16, 2009
Messages
32
On my centos 7 system I have apache running using php-fpm70 - and that works fine.
But I have now also installed nginx (listening on a different port) and would like the already installed and working php-fpm server.
My idea had been to create a user nginx, group nginx in DA which would give me a full setup with apache and php-fpm listening on the unix socket /usr/local/php70/sockets/nginx.sock
I set ownership of that socket to nginx:nginx with the idea that nginx runs as user nginx.
In /usr/local/directadmin/data/users/nginx/php/php-fpm70.conf I set
listen = /usr/local/php70/sockets/nginx.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 660
and restarted php-fpm70
Then, in the nginx configuration I set
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/usr/local/php70/sockets/nginx.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
and smugly - after restarting nginx - tried to display a PHP file - - - - - - but nothing!

Any idea what I am doing wrong would be very much appreciated :)
Thanks - Merlin
 
You want nginx in front of apache?
you can set webserver nginx_apache and build it.
 
Code:
cd /usr/local/directadmin/custombuild
./build update
./build update_da  #this command use to makesure is lastest version of DA.
./build set webserver nginx_apache
./build nginx_apache
./build rewrite_confs


after this if apache can't start or error something else
try
Code:
mv /etc/httpd /etc/httpd_bk
to rename old apache and try build again with step above
 
Thank you so much for the answers!
I did notice that option for the server earlier, but for all I can figure out this is nginx using apache as a proxy, and that is not what I am after. I want my regular websites to simply run with apache and php-fpm, but for some other application I need a bit more secure nginx and that should just use the already installed and running php-fpm. nginx would listen on completely different ports than apache and is completely independent of the apache installation.
 
In such case - only manual installation, like compiling from sources (in such case You can use latest OpenSSL and another benefits).
 
it's hard to explain but you can try config nginx and apache with custom template

directadmin use apache for base website so don't need to worry anything just config to use in port 80; 443;

and nginx just use for proxy to apache so you can try config template that use for other port and like second webserver

so then try change port with this
/usr/local/directadmin/directadmin c | grep port
Code:
port_80=80
port_443=443
port_8080=8080
port_8081=8081

and set with like this
/usr/local/directadmin/directadmin set port_80 80

==========================================
this my option and I can't confirm it working
I not recommended to manual complier nginx
 
again, many thanks for the suggestions.
In case you are running into a similar problem, here is how I finally got it to work:
I did not want to disturb my working installation of apache/php-fpm, so I fiddled some more to find out what might cause the problem because php-fpm was running, as well as nginx and both configurations seem to be correct, but nginx just did not want to connect to the PHP server.
I found the socat utility and used it with the following context
if echo /dev/null | socat UNIX:admin.sock - ; then echo connection OK; else echo connect ERROR; fi
which I tried on different .sock files and with different users. As root, I could connect to the socket, but when I run after a "su nginx" I could not connect and I got the error permission denied. I tried everything - even setting the socket file to 0666 - nothing! I can only imagine that there are other authentications used that I am not aware of.
So I tried the IP approach: listening on 127.0.0.1:9000 in the fpm config file and connecting to the same address in the nginx config file.....
And SUCCESS - no problem connecting. I guess I have a bit of a slowdown by using the IP interface but this will be a low traffic site, so it should not make much of a difference.
Out of curiosity: if somebody has an idea why the connection through the unix socket file did not work whole the IP method worked right away - I would appreciate finding out.
Cheers - Merlin
 
Usually, something left behind bothers me - and I just couldn't help with this open question, why the heck does the IP connection work and the unix socket does not - so I dug some more.
I now have it working with unix sockets, and I believe the reason it did not work was file ownership:
DA created the directory in which it stores all the socket files - /usr/local/php70/sockets - with apache:apache and0700. I had looked at the ownership and permissions of the created socket files IN this directory, and they were all correct. But as my nginx runs as nginx:nginx and the folder allows reading only to the owner apache, my nginx could never get to the socket file. Now I created my very own nginx socket file in /usr/local/php70/var/run and things magically started to work.
Just in case you run into something so silly.
 
Back
Top