Nginx and php-fpm in Docker

I am working on documenting the webserver / php workflow.

But since I am on Windows, I need to use a virtual machine. I chose boot2docker, which is Tiny Core Linux running on Virtualbox and adapted for Docker.

I selected three containers:

Boot2docker /www/contains my web projects and conf/which have the following tree:

conf
├───figfig.yml
└───nginx
        nginx.conf
        servers-global.conf
        servers.conf

Since it is docker-composenot available for boot2docker, I have to use figeverything to automate. Here is mine fig.xml:

mysql:
 image: mysql
 environment:
  - MYSQL_ROOT_PASSWORD=root
 ports:
  - 3306:3306

php:
 image: jprjr/php-fpm
 links:
  - mysql:mysql
 volumes:
  - /www:/srv/http:ro
 ports:
  - 9000:9000

nginx:
 image: nginx
 links:
  - php:php
 volumes:
  - /www:/www:ro
 ports:
  - 80:80
 command: nginx -c /www/conf/nginx/nginx.conf

Here is mine nginx.conf:

daemon off;

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log debug;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

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

    sendfile        off;

    keepalive_timeout  65;

    index    index.php index.html index.htm;

    include /www/conf/nginx/servers.conf;

    autoindex on;
}

And servers.conf:

server {
    server_name lab.dev;
    root /www/lab/;

    include /www/conf/nginx/servers-global.conf;
}

# Some other servers (vhosts)

And servers-global.conf:

listen 80;

location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    php:9000;
    include         /etc/nginx/fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME     /srv/http$fastcgi_script_name;
}

, ( , , ): lab.dev, ( , Windows), lab.dev/test_autoload/, File not found.. , , php-fpm , nginx :

nginx_1 | 2015/05/28 14:56:02 [error] 5#5: *3 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: 192.168.59.3, server: lab.dev, request: "GET /test_autoload/ HTTP/1.1",
upstream: "fastcgi://172.17.0.120:9000", host: "lab.dev", referrer: "http://lab.dev/"

, index.php lab/test_autoload/, . nginx /www/lab/test_autoload/index.php /srv/http/lab/test_autoload/index.php php.

, root / fastcgi_param SCRIPT_FILENAME, , .

, , root s, rewrite, / / s .., .

, , , , .

+4
3

- .

$fastcgi_script_name (, www/. , . :

# "generated" vhost
server {
    server_name lab.dev;
    root /www/lab/;

    listen 80;

    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    php:9000;
        include         /etc/nginx/fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME     /srv/http$fastcgi_script_name;
        # I need to add /lab after /srv/http because it requests PHP to look at the root of the web files, not in the lab/ folder
        # fastcgi_param   SCRIPT_FILENAME     /srv/http/lab$fastcgi_script_name;
    }
}

, lab/ , (root fastcgi_param), PHP , .json servers.conf. - , , .

+2

:

fastcgi_param   SCRIPT_FILENAME     /srv/http/$fastcgi_script_name;

:

fastcgi_param   SCRIPT_FILENAME     /srv/http$fastcgi_script_name;

.

+1

nginx.conf , ; nginx, work_processes .. nginx - http.

In http conf, the same thing, there are no types mime, default_type, logs sendfile at on configuration for boot2docker.

Your problem is clearly not a problem with Docker, but with the nginx configuration. Have you tested your docker launch app before using fig? Did it work?

0
source

All Articles