Hi,
I am running the nginx version: nginx/1.22 as a reverse proxy server on
CentOS Linux release 7.9.2009 (Core). When I hit http://mydomain.com/apis I
see the below message on the browser even if the upstream server php-fpm
server is up and running.
*{"errors": {"status_code": 502,"status": "php-fpm server is down"}}*
I have set the below in the nginx.conf file and attached the file for your
reference.
if ($upstream_http_content_type = "") {
add_header 'Content-Type' 'application/json' always;
add_header 'Content-Type-3'
$upstream_http_content_type$isdatatypejson"OK" always;
return 502 '{"errors": {"status_code": 502,"status":
"php-fpm server is down"}}';
}
# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor
preset: disabled)
Drop-In: /etc/systemd/system/php-fpm.service.d
└─override.conf
Active: active (running) since Thu 2022-12-15 15:53:31 UTC; 10s ago
Main PID: 9185 (php-fpm)
Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic:
0req/sec"
CGroup: /system.slice/php-fpm.service
├─9185 php-fpm: master process (/etc/php-fpm.conf)
├─9187 php-fpm: pool www
├─9188 php-fpm: pool www
├─9189 php-fpm: pool www
├─9190 php-fpm: pool www
└─9191 php-fpm: pool www
Dec 15 15:53:31 systemd[1]: Starting The PHP FastCGI Process Manager...
Dec 15 15:53:31 systemd[1]: Started The PHP FastCGI Process Manager.
#
Please guide me.
Best Regards,
Kaushal
{"errors": {"status_code": 502,"status": "php-fpm server is down"}}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221215/7e1da702/attachment.htm>
On Thu, Dec 15, 2022 at 9:53 PM Kaushal Shriyan <kaushalshriyan at gmail.com>
wrote:
> Hi,
>
> I am running the nginx version: nginx/1.22 as a reverse proxy server on
> CentOS Linux release 7.9.2009 (Core). When I hit http://mydomain.com/apis I
> see the below message on the browser even if the upstream server php-fpm
> server is up and running.
>
> *{"errors": {"status_code": 502,"status": "php-fpm server is down"}}*
>
> I have set the below in the nginx.conf file and attached the file for your
> reference.
>
> if ($upstream_http_content_type = "") {
> add_header 'Content-Type' 'application/json' always;
> add_header 'Content-Type-3'
> $upstream_http_content_type$isdatatypejson"OK" always;
> return 502 '{"errors": {"status_code": 502,"status":
> "php-fpm server is down"}}';
> }
>
> # systemctl status php-fpm
> ● php-fpm.service - The PHP FastCGI Process Manager
> Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled;
> vendor preset: disabled)
> Drop-In: /etc/systemd/system/php-fpm.service.d
> └─override.conf
> Active: active (running) since Thu 2022-12-15 15:53:31 UTC; 10s ago
> Main PID: 9185 (php-fpm)
> Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic:
> 0req/sec"
> CGroup: /system.slice/php-fpm.service
> ├─9185 php-fpm: master process (/etc/php-fpm.conf)
> ├─9187 php-fpm: pool www
> ├─9188 php-fpm: pool www
> ├─9189 php-fpm: pool www
> ├─9190 php-fpm: pool www
> └─9191 php-fpm: pool www
>
> Dec 15 15:53:31 systemd[1]: Starting The PHP FastCGI Process Manager...
> Dec 15 15:53:31 systemd[1]: Started The PHP FastCGI Process Manager.
> #
>
> Please guide me.
>
> Best Regards,
>
> Kaushal
>
> {"errors": {"status_code": 502,"status": "php-fpm server is down"}}
>
> Hi,
I have attached the file for your reference.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221215/6445d210/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginxtest.conf
Type: application/octet-stream
Size: 7363 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221215/6445d210/attachment.obj>
Hello!
On Thu, Dec 15, 2022 at 09:53:11PM +0530, Kaushal Shriyan wrote:
>
> I am running the nginx version: nginx/1.22 as a reverse proxy server on
> CentOS Linux release 7.9.2009 (Core). When I hit http://mydomain.com/apis I
> see the below message on the browser even if the upstream server php-fpm
> server is up and running.
>
> *{"errors": {"status_code": 502,"status": "php-fpm server is down"}}*
>
> I have set the below in the nginx.conf file and attached the file for your
> reference.
>
> if ($upstream_http_content_type = "") {
> add_header 'Content-Type' 'application/json' always;
> add_header 'Content-Type-3'
> $upstream_http_content_type$isdatatypejson"OK" always;
> return 502 '{"errors": {"status_code": 502,"status":
> "php-fpm server is down"}}';
> }
The "if" directive makes it possible to conditionally select
configuration to handle a request, and therefore can only use
information available before the request is handled. In your
case, before the request is sent to the upstream server. See
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html for
more details.
As such, $upstream_http_content_type will be always empty, since
there are no upstream response yet, and therefore the
configuration will always return 502. This matches your
observations.
An obvious fix would be to remove the configuration chunk in
question.
Instead, you probably need something like:
error_page 502 /502.json;
location = /502.json {
return 200 '{"errors": {"status_code": 502, "status": "php-fpm server is down"}}';
}
Hope this helps.
--
Maxim Dounin
http://mdounin.ru/
On Fri, Dec 16, 2022 at 1:38 AM Maxim Dounin <mdounin at mdounin.ru> wrote:
> Hello!
>
> On Thu, Dec 15, 2022 at 09:53:11PM +0530, Kaushal Shriyan wrote:
>
> >
> > I am running the nginx version: nginx/1.22 as a reverse proxy server on
> > CentOS Linux release 7.9.2009 (Core). When I hit
> http://mydomain.com/apis I
> > see the below message on the browser even if the upstream server php-fpm
> > server is up and running.
> >
> > *{"errors": {"status_code": 502,"status": "php-fpm server is down"}}*
> >
> > I have set the below in the nginx.conf file and attached the file for
> your
> > reference.
> >
> > if ($upstream_http_content_type = "") {
> > add_header 'Content-Type' 'application/json' always;
> > add_header 'Content-Type-3'
> > $upstream_http_content_type$isdatatypejson"OK" always;
> > return 502 '{"errors": {"status_code":
> 502,"status":
> > "php-fpm server is down"}}';
> > }
>
> The "if" directive makes it possible to conditionally select
> configuration to handle a request, and therefore can only use
> information available before the request is handled. In your
> case, before the request is sent to the upstream server. See
> http://nginx.org/en/docs/http/ngx_http_rewrite_module.html for
> more details.
>
> As such, $upstream_http_content_type will be always empty, since
> there are no upstream response yet, and therefore the
> configuration will always return 502. This matches your
> observations.
>
> An obvious fix would be to remove the configuration chunk in
> question.
>
> Instead, you probably need something like:
>
> error_page 502 /502.json;
>
> location = /502.json {
> return 200 '{"errors": {"status_code": 502, "status": "php-fpm
> server is down"}}';
> }
>
>
Thanks Maxim for the suggestion. I will try it out and keep you posted with
the testing as it progresses. I am obliged to this mailing list. Thanks in
advance.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221216/93349ca3/attachment.htm>
Hi Maxim,
I have a follow up question regarding the settings below in nginx.conf
where the php-fpm upstream server is processing all php files for Drupal
CMS.
fastcgi_intercept_errors off
proxy_intercept_errors off
User -> Nginx -> php-fpm -> MySQL DB.
For example if the php-fpm upstream server is down then nginx should render
502 bad gateway
if MySQL DB service is down then nginx should render
500 ISE.
Is there a way to render any of the messages or any custom messages to the
User from the php-fpm upstream server that should be passed to a client
without being intercepted by the Nginx web server. Any examples? I have
attached the file for your reference. Please guide me. Thanks in advance.
Best Regards,
Kaushal
On Fri, Dec 16, 2022 at 7:22 AM Kaushal Shriyan <kaushalshriyan at gmail.com>
wrote:
>
>
> On Fri, Dec 16, 2022 at 1:38 AM Maxim Dounin <mdounin at mdounin.ru> wrote:
>
>> Hello!
>>
>> On Thu, Dec 15, 2022 at 09:53:11PM +0530, Kaushal Shriyan wrote:
>>
>> >
>> > I am running the nginx version: nginx/1.22 as a reverse proxy server on
>> > CentOS Linux release 7.9.2009 (Core). When I hit
>> http://mydomain.com/apis I
>> > see the below message on the browser even if the upstream server php-fpm
>> > server is up and running.
>> >
>> > *{"errors": {"status_code": 502,"status": "php-fpm server is down"}}*
>> >
>> > I have set the below in the nginx.conf file and attached the file for
>> your
>> > reference.
>> >
>> > if ($upstream_http_content_type = "") {
>> > add_header 'Content-Type' 'application/json'
>> always;
>> > add_header 'Content-Type-3'
>> > $upstream_http_content_type$isdatatypejson"OK" always;
>> > return 502 '{"errors": {"status_code":
>> 502,"status":
>> > "php-fpm server is down"}}';
>> > }
>>
>> The "if" directive makes it possible to conditionally select
>> configuration to handle a request, and therefore can only use
>> information available before the request is handled. In your
>> case, before the request is sent to the upstream server. See
>> http://nginx.org/en/docs/http/ngx_http_rewrite_module.html for
>> more details.
>>
>> As such, $upstream_http_content_type will be always empty, since
>> there are no upstream response yet, and therefore the
>> configuration will always return 502. This matches your
>> observations.
>>
>> An obvious fix would be to remove the configuration chunk in
>> question.
>>
>> Instead, you probably need something like:
>>
>> error_page 502 /502.json;
>>
>> location = /502.json {
>> return 200 '{"errors": {"status_code": 502, "status": "php-fpm
>> server is down"}}';
>> }
>>
>>
> Thanks Maxim for the suggestion. I will try it out and keep you posted
> with the testing as it progresses. I am obliged to this mailing list.
> Thanks in advance.
>
> Best Regards,
>
> Kaushal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221216/bfaf48dd/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginxtest.conf
Type: application/octet-stream
Size: 7363 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221216/bfaf48dd/attachment-0001.obj>
Hello!
On Fri, Dec 16, 2022 at 11:53:40PM +0530, Kaushal Shriyan wrote:
> I have a follow up question regarding the settings below in nginx.conf
> where the php-fpm upstream server is processing all php files for Drupal
> CMS.
>
> fastcgi_intercept_errors off
> proxy_intercept_errors off
>
> User -> Nginx -> php-fpm -> MySQL DB.
>
> For example if the php-fpm upstream server is down then nginx should render
> 502 bad gateway
> if MySQL DB service is down then nginx should render
> 500 ISE.
>
> Is there a way to render any of the messages or any custom messages to the
> User from the php-fpm upstream server that should be passed to a client
> without being intercepted by the Nginx web server. Any examples? I have
> attached the file for your reference. Please guide me. Thanks in advance.
Not sure I understand what are you asking about.
With fastcgi_intercept_errors turned off (the default) nginx does
not intercept any of the errors returned by php-fpm.
That is, when MySQL is down and php-fpm returns 500 (Internal
Server Error), it is returned directory to the client. When
php-fpm is down, nginx generates 502 (Bad Gateway) itself and
returns it to the client.
--
Maxim Dounin
http://mdounin.ru/