我正在将我的Web服务器/PHP工作流程Docker化。
但是因为我在Windows上,我需要使用虚拟机。我选择了boot2docker,它是在Virtualbox中运行的Tiny Core Linux,并适用于Docker。
我选择了三个容器:
- nginx:官方nginx容器; - jprjr/php-fpm:一个php-fpm容器; - mysql:用于数据库。
在boot2docker中,
因为boot2docker不支持
我知道在两个容器中的
但是因为我在Windows上,我需要使用虚拟机。我选择了boot2docker,它是在Virtualbox中运行的Tiny Core Linux,并适用于Docker。
我选择了三个容器:
- nginx:官方nginx容器; - jprjr/php-fpm:一个php-fpm容器; - mysql:用于数据库。
在boot2docker中,
/www/
包含我的Web项目和conf/
,其中包含以下树形结构:conf
│
├───fig
│ fig.yml
│
└───nginx
nginx.conf
servers-global.conf
servers.conf
因为boot2docker不支持
docker-compose
,所以我必须使用fig
来自动化一切。这是我的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
这是我的 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;
}
还有 servers.conf
文件:
server {
server_name lab.dev;
root /www/lab/;
include /www/conf/nginx/servers-global.conf;
}
# Some other servers (vhosts)
还有 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/
,就会出现文件未找到
。我知道这是由于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/"
我知道在两个容器中的
lab/test_autoload/
目录下都有一个index.php
文件,我已经检查过了。在nginx
中,它位于/www/lab/test_autoload/index.php
和/srv/http/lab/test_autoload/index.php
中的php
。
我相信问题来自于root
和/或fastcgi_param SCRIPT_FILENAME
,但我不知道该如何解决。
我尝试了很多方法,比如修改root
、使用rewrite
规则、添加/删除一些/
等,但没有任何改变。
再次抱歉为这个配置添麻烦,但我认为描述我的环境是必要的。