0

I try to create an image from the image jelastic/nginxphp:1.18.0-php-7.4.10 to set up my existing Laravel project (to then put on Jelastic cloud). However, when I try to access localhost I get a ERR_EMPTY_RESPONSE error. I also tried to create a container from the jelastic/nginxphp:1.18.0-php-7.4.10 image but I have the same error

my Dockerfile

# ---------- Base ----------
FROM jelastic/nginxphp:1.18.0-php-7.4.10 AS base

# Set main params. The value local is equal to dev
ARG user=runner
ARG BUILD_ENV=local
ARG BUILD_DEBUG=true
ENV APP_HOME /var/www/webroot/ROOT
ENV ENV=$BUILD_ARGUMENT_ENV
ENV DEBUG_ENABLED=$BUILD_DEBUG

# it's the same configuration as the basic one but with the following changes  
# /var/www/webroot/ROOT -> /var/www/webroot/ROOT/public
COPY docker-conf/nginx/conf.d/nginx.conf /etc/nginx/nginx.conf

# Enable PHP extension
RUN yum install -y sed
RUN sed -i "s|;extension=pdo_mysql.so|extension=pdo_mysql.so|g" /etc/php.ini

# ---------- Builder ----------
FROM base as build

# Set working directory
WORKDIR $APP_HOME

COPY . .
RUN if [ "$BUILD_ARGUMENT_ENV" = "production" ];then COMPOSER_MEMORY_LIMIT=-1 composer update --optimize-autoloader --no-interaction --no-progress --no-dev; \
    else COMPOSER_MEMORY_LIMIT=-1 composer update --optimize-autoloader --no-interaction --no-progress; \
    fi

# Create system user
RUN useradd -ms /bin/bash $user

USER $user

the error produced

enter image description here

When I lauch this commande docker build -t myimage/backend ., I have this result:

[+] Building 278.0s (13/13) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                               0.0s
 => => transferring dockerfile: 32B                                                                                                                                                                                                0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                  0.0s
 => => transferring context: 34B                                                                                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/jelastic/nginxphp:1.18.0-php-7.4.10                                                                                                                                                     0.0s
 => [base 1/4] FROM docker.io/jelastic/nginxphp:1.18.0-php-7.4.10                                                                                                                                                                  0.0s
 => [internal] load build context                                                                                                                                                                                                  0.1s
 => => transferring context: 26.72kB                                                                                                                                                                                               0.1s
 => CACHED [base 2/4] COPY docker-conf/nginx/conf.d/nginx.conf /etc/nginx/nginx.conf                                                                                                                                               0.0s
 => [base 3/4] RUN yum install -y sed                                                                                                                                                                                             27.8s
 => [base 4/4] RUN sed -i "s|;extension=pdo_mysql.so|extension=pdo_mysql.so|g" /etc/php.ini                                                                                                                                        0.5s
 => [build-app 1/4] WORKDIR /var/www/webroot/ROOT                                                                                                                                                                                  0.0s
 => [build-app 2/4] COPY . .                                                                                                                                                                                                       0.1s
 => [build-app 3/4] RUN if [ "$BUILD_ARGUMENT_ENV" = "production" ];then COMPOSER_MEMORY_LIMIT=-1 composer update --optimize-autoloader --no-interaction --no-progress --no-dev;     else COMPOSER_MEMORY_LIMIT=-1 composer upd  245.9s
 => [build-app 4/4] RUN useradd -ms /bin/bash runner                                                                                                                                                                               0.5s
 => exporting to image                                                                                                                                                                                                             3.0s
 => => exporting layers                                                                                                                                                                                                            2.9s
 => => writing image sha256:98c32ac25564198547a767153df9c410467aabdf64c9115158c301272f2de3cc                                                                                                                                       0.0s
 => => naming to docker.io/myimage/backend  

Here is the command I use to create a container:

C:\Users\Myusername\Documents\projet>docker run -dp 8000:80 myimage/backend
c5c00082d17677bfb599decab892e18de468ab13380ed1d23a38cbf3c06511ee

When I lauch this command: docker run -dp 8000:80 jelastic/nginxphp:1.18.0-php-7.4.10, I have the same error

here is my configuration file for the nginx server

#user  nobody;
worker_processes  auto;
worker_rlimit_nofile 2048;

#load_module modules/ngx_http_modsecurity_module.so;

error_log  /var/log/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  2048;
}


http {
    server_tokens off;
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 100m;

    log_format  main  '$remote_addr:$http_x_remote_port - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      '"$host" sn="$server_name" '
                      'rt=$request_time '
                      'ua="$upstream_addr" us="$upstream_status" '
                      'ut="$upstream_response_time" ul="$upstream_response_length" '
                      'cs=$upstream_cache_status' ;

    access_log  /var/log/nginx/access.log main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;
    gzip_types text/plain text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript;

    # Websocket support
    #upstream websocket {
    #    server 127.0.0.1:<PORT>;
    #}

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;

        #charset koi8-r;

        access_log  /var/log/nginx/host.access.log;
        include /etc/nginx/aliases.conf;

        #location /ws {
        #    proxy_pass http://websocket;
        #    proxy_http_version 1.1;
        #    proxy_set_header Upgrade $http_upgrade;
        #    proxy_set_header Connection "Upgrade";
        #}
        if ($http_x_remote_port = '' ) {
            set $http_x_remote_port $remote_port;
        }

        #modsecurity on;
        #modsecurity_rules_file /etc/nginx/conf.d/modsecurity/modsec_includes.conf;

        location / {
            root   /var/www/webroot/ROOT/public;
            index  index.html index.htm index.php;

            location ~ \.php$ {
                location ~ /\. { deny all; access_log off; log_not_found off; }
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/run/php-fpm.socket;
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
                fastcgi_param DOCUMENT_ROOT $realpath_root;
                fastcgi_param PATH_INFO $fastcgi_script_name;
            }

        }
        index  index.php index.html index.htm;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        location ~ \.php$ {
            proxy_pass   http://127.0.0.1;
        }
        location ~ ^/\.well-known {    root /var/www/webroot/ROOT;  allow all;}
        location ~ /\.well-known {       root /var/www/webroot;  allow all;}
    location ~ /\. { deny all; access_log off; log_not_found off; }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    location ~ \.php$ {
        location ~ /\. { deny all; access_log off; log_not_found off; }
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm.socket;
        fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT /var/www/webroot;
        }

    }

include /etc/nginx/conf.d/*.conf;

}
Virtuozzo
  • 1,993
  • 1
  • 10
  • 13
diego
  • 408
  • 8
  • 21
  • 1
    What does the logs of the container says? – β.εηοιτ.βε Nov 25 '20 at 17:29
  • What is the outcome of the build from your dockerfile ? How are you launching the container from the resulting image ? You try to access your site on the localhost address: did you map the 80/443 ports from the container ? If you did all that correctly, are there any errors in your container's log ? Please edit your question and add details. – Zeitounator Nov 25 '20 at 17:30
  • there is no log file that is generated (The places I will look for the logs are: `/var/log/nginx/access.log` & `logs/host.access.log`) – diego Nov 25 '20 at 17:52
  • Untrue. A container generates logs, and send them back to docker. See: https://docs.docker.com/engine/reference/commandline/logs/ – β.εηοιτ.βε Nov 25 '20 at 18:57
  • Can you provide us with the conf file from this step? COPY docker-conf/nginx/conf.d/nginx.conf /etc/nginx/nginx.conf – Virtuozzo Nov 25 '20 at 20:54
  • @β.εηοιτ.βε I know the command but the output is empty – diego Nov 26 '20 at 08:12
  • @Jelastic Is there a command to run the nginxphp server? If so, what is it? – diego Nov 26 '20 at 12:03

1 Answers1

2

After extensive research and testing. I managed to make a laravel image work from the image of jelastic/nginxphp:1.18.0-php-7.4.10

For those interested, I leave you my solution. If you have a better solution or an improvement, don't be afraid to show your solution

Dockerfile

# ---------- Base ----------
FROM jelastic/nginxphp:1.18.0-php-7.4.10 AS base

# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
        && ln -sf /dev/stderr /var/log/nginx/error.log

COPY docker-conf/nginx/conf.d/nginx.conf /etc/nginx/nginx.conf


## Set main params. The value local is equal to dev
ARG user=nginx
ARG BUILD_ENV=local
ARG BUILD_DEBUG=true
ENV APP_HOME /var/www/webroot
ENV ENV=$BUILD_ARGUMENT_ENV
ENV DEBUG_ENABLED=$BUILD_DEBUG


## Enable PHP extension
RUN yum install -y sed
RUN sed -i "s|;extension=pdo_mysql.so|extension=pdo_mysql.so|g" /etc/php.ini

## ---------- Builder ----------
FROM base as build-backend
#
## Set working directory
WORKDIR $APP_HOME
RUN rm -rf index.php

ADD ./ .
RUN chmod -R 777 storage

RUN if [ "$BUILD_ARGUMENT_ENV" = "production" ];then COMPOSER_MEMORY_LIMIT=-1 composer update --optimize-autoloader --no-interaction --no-progress --no-dev; \
    else COMPOSER_MEMORY_LIMIT=-1 composer update --optimize-autoloader --no-interaction --no-progress; \
    fi
CMD service php-fpm start && nginx -g "daemon off;"

nginx.conf

#user  nobody;
worker_processes  auto;
worker_rlimit_nofile 2048;

#load_module modules/ngx_http_modsecurity_module.so;

error_log  /var/log/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  2048;
}


http {
    server_tokens off;
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 100m;

    log_format  main  '$remote_addr:$http_x_remote_port - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      '"$host" sn="$server_name" '
                      'rt=$request_time '
                      'ua="$upstream_addr" us="$upstream_status" '
                      'ut="$upstream_response_time" ul="$upstream_response_length" '
                      'cs=$upstream_cache_status' ;

    access_log  /var/log/nginx/access.log main;
    sendfile        on;
    keepalive_timeout  65;

    gzip  on;
    gzip_types text/plain text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript;

    server {
        listen       80 ;
        listen       [::]:80;
        server_name  _;

        charset utf-8;

        access_log  /var/log/nginx/host.access.log;
        error_log  /var/log/nginx/host.error.log;
        include /etc/nginx/aliases.conf;

        index index.php;
        root   /var/www/webroot/public;

        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options "nosniff";


        #modsecurity on;
        #modsecurity_rules_file /etc/nginx/conf.d/modsecurity/modsec_includes.conf;

        if ($http_x_remote_port = '' ) {
           set $http_x_remote_port $remote_port;
        }

        # enforce NO www
        if ($host ~* ^www\.(.*)) {
            set $host_without_www $1;
            rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
        }
        # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
        if (!-e $request_filename)
        {
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
        }

        error_page 404 /index.php;

        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }
        #location /ws {
        #    proxy_pass http://websocket;
        #    proxy_http_version 1.1;
        #    proxy_set_header Upgrade $http_upgrade;
        #    proxy_set_header Connection "Upgrade";
        #}


        # serve static files directly
        location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
            access_log off;
            expires max;
            log_not_found off;
        }

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
            #location ~ /\. { deny all; access_log off; log_not_found off; }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/run/php-fpm.socket;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            fastcgi_param PATH_INFO $fastcgi_script_name;
        }

        location ~ /\.(?!well-known).* {
                deny all;
        }
    }

    include /etc/nginx/conf.d/*.conf;

}
diego
  • 408
  • 8
  • 21