我开始与Docker和nginx,我试图设置两个容器环境中运行:一方面简单的搬运工,组成:nginx的和PHP
nginx:latest
php:fpm
在另一边
我遇到了php-fpm的麻烦:我总是得到一个502错误的网关错误。
我的设置非常简单($TEST_DIR
是我的工作目录)。
我的码头工人组成的配置TEST_DIR/docker-compose.yml
:
nginx:
image: nginx
ports:
- "8080:80"
volumes:
- ./www:/usr/share/nginx/html
- ./conf/nginx.conf:/nginx.conf
- ./logs/nginx:/var/log/nginx
links:
- php:php
command: nginx -c /nginx.conf
php:
image: php:fpm
ports:
- "9000:9000"
volumes:
- ./www:/var/www/html
nginx的配置$TEST_DIR/conf/nginx.conf
:
user nginx;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
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;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
open_file_cache max=100;
upstream php-upstream {
server php:9000;
}
server {
listen 80;
server_name localhost;
location/{
root /usr/share/nginx/html;
index index.html index.htm;
}
# Pass PHP scripts to PHP-FPM
location ~* \.php$ {
fastcgi_pass php-upstream;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/php_error.log;
access_log /var/log/nginx/php_access.log;
}
}
daemon off;
然后,我把我的PHP内容在同一目录作为我docker-compose.yml
:
$TEST_DIR/www/test.php
<?php phpinfo(); ?>
如果我使用docker-compose up
启动的基础设施,然后去localhost:8080/test.php
,然后我得到502网关错误 和nginx的以下错误:
[error] 6#6: *1 connect() failed (113: No route to host) while connecting to upstream, client: 172.17.42.1, server: localhost, request: "GET /phpinsfo2.php HTTP/1.1", upstream: "fastcgi://172.17.0.221:9000", host: "localhost:8080"
是什么原因造成的错误?
我不知道它是否解决了问题,但它似乎没有在量的定义为PHP的容器一个错字'./www:/ var/wwww/html' –
我验证了修复'./www:/ var/wwww/html'中的拼写错误可以让我看到'/ test.php'页面的内容。尽管你的错误'connect()失败(113:没有路由到主机)'可能表明我无法重现的问题。您是否正在使用码头工人和码头工人的最新版本? – Thomasleveil
我正在使用** docker 1.7.0 build 0baf609 **和** docker-compose 1.3.1 **。 事件与错字固定的,我仍然有同样的问题: nginx的服务器服务于正确的静态文件,但是PHP文件不被发送到PHP-FPM,我仍然得到502错误网关错误 的一点是,我不明白,如果请求路由到PHP FPM或不... ...我怎么测试? – Clement