nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.25k stars 320 forks source link

nginx unit php server stops responding when using supervisor #1309

Closed kapyaar closed 2 weeks ago

kapyaar commented 2 weeks ago

I have an nginx Unit+Php container with the following docker file

FROM unit:1.32.1-php8.2
RUN apt-get update && apt-get install -y supervisor
EXPOSE 80
WORKDIR /var/www/html/
COPY config.json /docker-entrypoint.d/config.json

And If I run this, it works fine, index.php loads correctly. Now, I want to use supervisor to start a php script to run as daemon. This is a kafkaConsumer with a while loop. Below are the files

[supervisord]
nodaemon=true

[program:nginx-unit]
command=unitd --no-daemon
stdout_logfile_maxbytes = 0
stderr_logfile_maxbytes = 0
stdout_logfile=/var/log/unit.log
stderr_logfile=/var/log/unit.log
autostart=true
autorestart=true

[program:kafkaTestConsumer]
command=php /var/www/html/PhpScriptThatRunsContinuously.php
autostart=true
directory=/var/www/html/
autorestart=true
stdout_logfile=/dev/stdout
stderr_logfile=/dev/stderr
stdout_maxbytes=0 # need these lines due to [https://github.com/Supervisor/supervisor/issues/935][1]
stderr_maxbytes=0
stdout_logfile_maxbytes = 0
stderr_logfile_maxbytes = 0

And a simple php script for testing.

<?php
while(1){
    sleep(3);
    echo ".";
}
?>

However, If I add the following line to Dockerfile to start supervisor,

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

Then, the daemon php script does start, but the php server (http://localhost/) stops responding, with the following message

localhost didn’t send any data.
ERR_EMPTY_RESPONSE

Any help much appreciated.

lcrilly commented 2 weeks ago

Which service is listening on port 80?

Can you share your Unit configuration?

kapyaar commented 2 weeks ago

Sorry, I should have added it in the first place.

{
  "listeners": {
    "*:80": {
      "pass": "applications/php"
    }
  },
  "applications": {
    "php": {
      "type": "php",
      "root": "/var/www/html/",
      "processes": 1,
      "index":"index.php"
    }
  }
}

Compose

services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
    working_dir: /var/www/html/
    container_name: phpApp
    ports:
      - 80:80
    volumes:
      - .:/var/www/html/