Nginx connect() failed error - php

I don't know why I got this error every time I tried to open the page:
2013/04/06 17:52:19 [error] 5040#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost:8080"

I resolved it, it was a configuration file issue, I added:
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

For me the problem was my php-fpm service wasn't running. You can check it by running:
service php-fpm status
and start it by running
service php-fpm start
Sometimes php-fpm might have broken instances running, preventing a restart. This command is a clean way to clear them out and restart php-fpm
killall -9 php-fpm; service php-fpm restart

update your configurations as mentioned before:
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
but don't forget to restart both nginx server and php-fpm after updating
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php-fpm restart

I found I had this same issue with PHP7 running in Docker on a Debian Jessie (8.3) instance.
running command 'ps -aux' showed that php-fpm wasn't running
running 'php-fpm -D' brought it up as deamonized process.
Rerunning 'ps -aux' showed that php-fpm was indeed running
Refreshing my test page showed me the servers PHP info.
Added 'php-fpm -D' to my start.sh script so that things started every time the container is loaded.
Hope this helps someone.

Use fastcgi_pass unix:/var/run/php5-fpm.sock; only nginx and php install same server. If nginx and php install in other server you must use fastcgi_pass ip server:port;

Related

Connect host nginx and msql with a docker container of php5-fpm

I have a legacy Wordpress installation that run with Nginx/MySQL and php5-fpm and I have to move it to a recent VPS that features php7-fpm.
I'd like to leverage the new host VPS already installed Nginx/MySQL and install and use a container for managing php5 requests.
I pulled the official php5-fpm image from Docker Hub
docker pull php:5.6-fpm-alpine
... then I run the the image remapping the port 9000 where php5-fpm is listening and mounting the wordpress root folder (uncertain about that) and mysql socket, without -d flag in order to see the logs live:
docker run --name phpFpm5.6 -p 127.0.0.1:9999:9000 -v /home/ubuntu/www/html:/var/www/html -v /var/run/mysqld/mysqld.sock:/tmp/mysql.sock php:5.6-fpm-alpine
Here's the console logs:
[21-Aug-2017 12:36:19] NOTICE: fpm is running, pid 1
[21-Aug-2017 12:36:19] NOTICE: ready to handle connections
172.17.0.1 - 21/Aug/2017:12:37:09 +0000 "GET /index.php" 404
172.17.0.1 - 21/Aug/2017:12:39:30 +0000 "GET /index.php" 404
When I request the index page from a browser, I'm getting a 404 (not found) response.
Nginx directive:
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Any clue is really appreciated.
Thanks in advance.
Best,
Luca
Think of container as the remote server. Now the mapping of ports that you are doing 9999:9000 tells docker to connect port number 9999 on host to port number 9000 of the container.
Now in your nginx directive, the one running inside container, you are redirecting at 9999. Instead, it should be 9000.
According to your scenario, all resources are served by the container at port 9999, but port 9999 of container is not accessible to host.

Nginx throwing 502 Bad Gateway on blog (subdomain)

So, I was trying to setup mysite.com/blog initially, but got pretty fed up with it, so i setup blog.mysite.com instead.
It successfully loads the index file: index.htm, but if i try to access a file info.php it fails saying: 502 bad gateway, i checked /var/log/nginx/error.log and it says:
2016/12/17 09:24:13 [error] 1042#0: *4 connect() failed (111:
Connection refused) while connecting to upstream, client: x.xx.xx.xx,
server: blog.mysite.com, request: "GET /info.php HTTP/1.1", upstream:
"fastcgi://127.0.0.1:9000", host: "blog.mysite.com"
I installed php via: sudo apt-get install php5-fpm php5-mysql from this tutorial: link
My nginx config in /etc/nginx/sites-enabled/myblog is:
server {
listen 80;
root /home/www/flask-deploy/myblog;
fastcgi_index index.php;
index index.html index.htm index.nginx-debian.html;
server_name blog.mysite.com www.blog.mysite.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
What am I doing wrong?
Thank you so much!
First of all, your nginx config has bad path to php-fpm.sock. (You error.log is right ;) )
1) Which PHP version are you using? Use:
php -v
2) Be sure php-fpm is installed it is very important for nginx
sudo apt-get install php-fpm
3) Set correct path to php-fpm
For example, I use PHP7.0 and my path is:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
Some my projects are running on PHP5.6 and path is:
fastcgi_pass 127.0.0.1:9000;
4) Restart nginx and php-fpm (php5.6-fpm, php7.0-fpm...)
sudo service nginx restart
sudo service php5.6-fpm restart

unable to get hhvm working with nginx

I have nginx and hhvm installed and running as processes on a ubuntu VM. The configs are copied below. I have an index.php file in /usr/share/nginx/html (pointed to by nginx) but when I try to access the site beign served by nginx, I get the following error about hhvm:
/var/log/nginx/error.log
2016/10/04 12:03:05 [crit] 12443#0: *1 connect() to unix:/var/run/hhvm/hhvm.sock failed (2: No such file or directory) while connecting to upstr
eam, client: xx.xxx.xxx.xxx, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/hhvm/hhvm.sock:", host: "xx.xx.xx.xx"
Nginx config (part of config)
server {
listen 80 default_server;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
index index.php;
try_files $uri $uri/ $uri/index.php$args /index.php$args;
}
location /mysql {
index index.php;
}
location ~* \.(php)$ {
try_files $uri = 404;
location ~ \..*/.*\.php$ {return 404;}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I have checked - bothh nginx and hhvm processes are running. Any thoughts on how to troubleshoot this further?
Update:
I changed the server.ini file in /etc/hhvm to the following and restarted the service but it does not appear to have done the job
hhvm.server.file.socket=/var/run/hhvm/hhvm.sock
I commented out the 9000 port being used previously.
Update:
After making the server.init change and restarting hhvm, I get the following error in /var/log/hhvm/error.log:
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to start page server
Shutting down due to failure(s) to bind in HttpServer::runAndExitProcess
The /var/run/hhvm directory is owned by www-data
I ended up running hhvm on port 9000 and pointed nginx (fasgcgi_pas) to point to the port (instead of using the file socket option).

PHP5-FPM secondary pool not starting (111: Connection refused)

I have the default [www] pool up and running with no problems. I wanted to run another one to separate the process for another site.
I have the following conf:
/etc/php5/fpm/pool.d/site2.conf
[site2]
user = site2
group = www-data
listen = /var/run/php5-fpm-site2.sock
listen.owner = www-data
listen.group = www-data
/etc/nginx/sites/site.net
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm-site2.sock;
fastcgi_index index.php;
include fastcgi_params;
}
The socket/user do exist in /var/run and the ownership/permissions are all OK however when I run the php5-server only the default www is starting and I get
2016/04/26 16:30:24 [error] 27908#0: *35895 connect() to unix:/var/run/php5-fpm-site2.sock failed (111: Connection refused) while connecting to upstream,
What do you think?
It was a problem with php5-fpm process, for some reason the master process was terminated so any command would fail (it wasn't restarting at all).
So I fixed with:
sudo pkill php5-fpm; sudo service php5-fpm start
This could be related Ubuntu php5-fpm throws unknown instance on reload

unable to implement php with nginx

I have nginx working with arch linux. I am having trouble adding php and fastcgi. I installed the php and php-fpm packages. php-fpm service is on. When I access a file with a php extension, the browser displays the nginx error page and I get the following nginx error log message added:
2013/01/02 22:39:43 [error] 721#0: *27 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.13, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.1.19"
the contents of the php file seem to make no difference. I have been unable to locate php error log or create my own. I added the following to /etc/php/php.ini:
error_log = /var/log/php_error.log
and I made the file world writable but nothing goes there. I added the following to /etc/nginx/nginx.conf:
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi.conf;
}
uncommenting the commented lines changes nothing. Commenting the uncommented lines changes the browser page displayed from error page to file not found page.
Any help would be greatly appreciated. Thanks in advance.
Try changing your configuration file to this:
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
I figured it out. I had to uncomment a line in the php-fpm.conf file to have fastcgi listen on the right port.

Categories