Kevin
Kevin

Reputation: 5092

Using nginx in a php container

I have this Dockerfile based on php-fpm

FROM php:7.1-fpm

RUN apt-get -y update && apt-get -y upgrade

# Basics
RUN apt-get -y install vim nano git curl cron zsh

# www-data user
RUN usermod -u 1000 www-data

RUN apt-get update \
    && apt-get install -y nginx \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
    && echo "daemon off;" >> /etc/nginx/nginx.conf

ADD default.conf /etc/nginx/sites-available/default

ADD . /var/www
WORKDIR /var/www

EXPOSE 80 9000
CMD ["nginx"]

I have installed nginx in this image and added configuration: default.conf

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www;
    index index.html index.htm index.php;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
}

This can load very well a html file but I don't know how to load a php file when I'm using a based php image.

I don't find the php socket to use fast cgi mode in this php-fpm image.

With a separetad php-fpm container I'll manage it that way:

location ~ ^/(index)\.php(/|$) {
        fastcgi_pass php-fpm:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }

But I want to use one single container. How can I do it? How can I change this line?

fastcgi_pass php-fpm:9000;

Upvotes: 0

Views: 2145

Answers (2)

Bukharov Sergey
Bukharov Sergey

Reputation: 10215

You can use existed PHP-FPM +NGINX container. Or you can look at Container's dockerfile it can provide some help.

Upvotes: 0

nuster cache server
nuster cache server

Reputation: 1791

There are several ways,

  1. put php and nginx command in a script, say run.sh, then CMD run.sh.
  2. use process manager like supervisord

Upvotes: 1

Related Questions