502 Bad Gateway with nginx and php7.0-fpm on docker - nginx

I have created docker image, which includes the Debian packages nginx-full, php7.0, php7.0-fpm, php-zmq and application code written in PHP.
When I am trying to invoke the application from a browser (basically calling zeroMQ), I receive a 502 bad gateway error. How can I find out whether it is a server or a code problem?
Tried changing the permission to the socket file and
not able to print the PATH_INFO variable.
Nginx log:
157#157: *622 recv() failed (104: Connection reset by peer) while reading response header from upstream,
PHP-FPM log:
[02-Apr-2018 16:05:26] WARNING: [pool www] child 197 exited on signal 11 (SIGSEGV) after 79.435089 seconds from start
[02-Apr-2018 16:05:26] NOTICE: [pool www] child 203 started
nginx configuration:
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include /etc/nginx/fastcgi_params;
}
PHP-FPM configuration :
user = www-data
group = www-data
//tried 127.0.0.1:900 but did not work
listen = /run/php/php7.0-fpm.sock
After receiving the error, when I do php-fpm reload, the error goes off. But then will happen again.

It is a known bug, try using this update:
Dockerfile

Related

nginx configuratio : alias and 404 error

My actual problem was that I wanted to make my "site.com/blog/index.php" direct to "/srvX/www/blog/caller/index.php". Althought it would be very straightforward to direct to "/srv/www/blog/index.php" using "root /srv/www/", that's not what I wanted. I discovered "alias", and it seem to do what I want.
1)First try :
server {
listen 80;
server_name _;
root /srv/www/blog/pages;
index index.php;
location /blog {
alias /srv/www/blog/caller;
}
}
There trying site.com/blog get me a 404 not found, and nothing pop into /var/log/nginx/error.log
1)Second try to know what happens :
If I change "alias /srv/www/blog/caller;" to a bad path, let say "alias /srvX/www/blog/caller;" I actually got the same behaviour in my browser, but
I can see in /var/log/nginx/error.log :
[error] 7229#0: *1 "/srvX/www/blog/caller/index.php" is not found (2: No such file or directory), client: 192.168.1.200, server: 192.168.1.221, request: "GET /blog/ HTTP/1.1", host: "192.168.1.221"
Conclusion : I don't know what's hapenning there : it seem clear that nginx get the file in my first try, but it sends the 404 error to the browser with no reason I could think of, while when specyfiyng a wrong path, it tells me right away. :/*
edit
Well, I found the solution. Basically it totally works from nginx, the problem was from php-fpm who lose his mind when using alias into nginx. What you need to do is doing a sublocation of aliased locations adding :
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
Now it works.
The fact that nginx was giving a 404 error without anything in the nginx's logs, was that php-fpm was the one failing to serve.
The problem is that you have no instructions on how to deal with the php script. To solve this issue the following:
Add the following code to your nginx.conf file within the server tags or if you have created that in your conf.d folder add it to that file.
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
That will solve that problem but also in the file:
/etc/php-fpm.d/www.conf
Ensure that listen.owner is set to listen.owner = nginx
Ensure that listen.group is set to listen.group = nginx
Restart both services and it should work.
If not ensure your document root and all files with that directory are owned by the user nginx and the group nginx.
If not you can do this by using the following:
chown -R nginx:nginx documentroot
And keep doing that but adding /* each time until you reach an error.
Hope everything works out for you!!

Getting Fatal Errors in Nginx to Be Shown in the Browser

EDIT:
I have done everything suggested in the duplicate answers and nothing works. Here is my PHP info:
This is a specific issue with nginx and stderr messages and is not a generic "how do I turn on PHP error reporting" issue.
While developing I'm getting blank pages in my browser whenever I create a fatal error in PHP with a typo or just my bad programming ;). It's super annoying for me to have to view the raw nginx error log file to see the fatal errors and find the line numbers where they are. I can't seem to find how to make nginx display PHP fatal errors in the browser. Here is the relevant part of my nginx config:
location #fpm {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_NAME index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param PATH_INFO $path_info;
}
Here's an example error that shows up in my error log and then results in a blank browser page:
2014/01/04 14:53:52 [error] 20082#0: *403 FastCGI sent in stderr:
"PHP message: PHP Fatal error: Cannot redeclare class ClassName in FilePath on line 356"
while reading response header from upstream, client: 192.168.1.10,
server: servername, request: "GET URLPATH HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "host",
referrer: "referer"
Here is my PHP-FPM conf:
http://pastebin.com/QkCTbBYj
And my PHP-FPM pool conf:
http://pastebin.com/TZfZ8d7G
And my PHP-FPM php.ini:
http://pastebin.com/RsXRxduf
I would love if anyone could shed some light on what I could do to get these errors to show up!
try setting catch_workers_output to yes in pool config:
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
catch_workers_output = yes
if that doesn't work you might have this bug:
https://bugs.php.net/bug.php?id=61045

nginx + php-fpm + pidora(fedora) on raspberry

I would like to make the configuration what mentioned in the subject.
If I start the nginx I see this error message in /var/log/nginx/error.log
*1 connect() to unix:127.0.0.1:9000 failed (2: No such file or directory) while connecting to upstream
I tried to set with socket. I get the following error
unix:/var/run/php5-fpm.sock failed (2: No such file or directory)
Seems the nginx need a file or not the path is bad. Exactly I not understand how can I solve it,
Here is my nginx settings
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/nginx/fastcgi_params; }
when I tried with socket I used this ( fastcgi_pass unix:/var/run/php-fpm/php5-fpm.sock;)
I change in /etc/php-fpm/www.conf only the "listen" attribute depends on fastcgi_pass.
Anyone has an idea how can I solve it?
Update:
I changed fastcgi_pass unix:127.0.0.1:9000 to fastcgi_pass 127.0.0.1:9000
In this case I got the following error
*1 connect() failed (111: Connection refused) while connecting to upstream,
And the following messages when I started the php-fpm
Oct 17 09:30:31 raspi php-fpm[6605]: [17-Oct-2013 09:30:31] ALERT: [pool www] user has not been defined
Oct 17 09:30:31 raspi php-fpm[6605]: [17-Oct-2013 09:30:31] ERROR: failed to post process the configuration
Oct 17 09:30:31 raspi php-fpm[6605]: [17-Oct-2013 09:30:31] ERROR: FPM initialization failed
Oct 17 09:30:31 raspi systemd[1]: php-fpm.service: main process exited, code=exited, status=78/n/a
Oct 17 09:30:31 raspi systemd[1]: Unit php-fpm.service entered failed state
Solved
I had to set the following users in the php-fpm
user
group
listen.owner
listen.group

Nginx + php-fpm on Amazon Linux = exited on signal 11

Amazon Linux lastest
PHP 5.4.19 (cli) (built: Sep 3 2013 23:19:23)
nginx version: nginx/1.2.9
installed PHP-FPM: PHP 5.4.19 (fpm-fcgi) (built: Sep 3 2013 23:22:01)
phpinfo() is working
pma.nginx.conf:
server {
listen 80;
server_name pma.my.server;
root /usr/share/phpmyadmin;
index index.php;
charset UTF-8;
access_log /var/log/myserver/pma.access.log;
error_log /var/log/myserver/pma.error.log;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /usr/share/phpmyadmin/;
fastcgi_intercept_errors on;
}
}
/var/log/myserver/pma.error.log:
[error] 21374#0: *13 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 1.0.255.202, server: pma.my.server, request: "GET /js/get_image.js.php?theme=pmahomme HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "pma.my.server", referrer: "http://pma.my.server/"
/var/log/php-fpm/error.log
NOTICE: fpm is running, pid 21598
NOTICE: ready to handle connections
WARNING: [pool www] child 21600 exited on signal 11 (SIGSEGV) after 12.862493 seconds from start
NOTICE: [pool www] child 21614 started
WARNING: [pool www] child 21602 exited on signal 11 (SIGSEGV) after 13.768522 seconds from start
NOTICE: [pool www] child 21617 started
/var/log/messages
kernel: [12499.658777] php-fpm[21603]: segfault at 0 ip 00000000005c5a39 sp 00007fffb44d6d60 error 4 in php-fpm[400000+31c000]
I don't have big experience with Nginx and FastCGI, so I need your help. Do you have any ideas? Thanks in advance
it appears that PHP is trying to write session data to disk in a directory that's not actually writable, namely /var/lib/php/session.
Thanks to Michael Hampton
The problem is php unable to write session to file but it not necessarily located in /var/lib/php/session
You can check and change it by using session_save_path
It appears there are a lot of things that can cause this, but if you are running a Magento website also check to see if any shopping cart rules were changed recently and see this relevant post. That was the solution for me.
The code in this file /js/get_image.js.php cause segment fault.
You can use core dump to view the backtrace.
Nginx Core dump

zero size shared memory zone "proxied" in nginx

I installed nginx with nginx-extras to get (Http Upload Progress Module).
Then i tried to use it following this documentation ( example on the bottom of the page ) -> http://wiki.nginx.org/HttpUploadProgressModule. After inserting this one line (track_uploads proxied 30s;) in my configuration , i get the following error
nginx: [emerg] zero size shared memory zone "proxied"
Somewhere on the internet i found , that someone suggested to insert upload_progress proxied 10m; into nginx.conf , and after inserting it i started geting the following error:
nginx: [emerg] the size 10485760 of shared memory zone "proxied"
conflicts with already declared size 0 in /etc/nginx/nginx.conf:75
This the part of the config , where are inserted this line....
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /home/cha0s/learnphp$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
track_uploads proxied 1m;
}
So the question is , what should i write in nginx.conf to resolve this error ? Thanks in advance.
You should put upload_progress proxied 1m; before your server block, like it is in the example.

Resources