我正在使用docker制作两个容器。一个nginx容器和另一个php-fpm容器,但我想从头开始设置它们。
它们在构建正确后运行,但它们不会相互通信。当我在浏览器中运行127.0.0.1:8883时,我得到 502 bad gateway
我听说过必须关闭的deamon。这样就完成了。
我在/etc/php/7.0/fpm/pool.d/www.conf中设置了127.0.0.1:9000听,也没关系。
我读过有关上游nginx但它是针对proxy_pass指令的。
这里是我的docker-compose.yml
version: '3'
services:
web_1:
build: nginx
ports:
- "8887:80"
links:
- php_1
container_name: 'web_1'
php_1:
build: php
ports:
- "9000:9000"
名为php_1的服务链接到web_1以在php容器中设置fastcgi
我的nginx dockerfile
FROM debian:stretch
RUN echo 'deb http://nginx.org/packages/debian/ squeeze nginx' >> /etc/apt/sources.list
RUN echo 'deb-src http://nginx.org/packages/debian/ squeeze nginx' >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y nginx
RUN echo 'server {\
listen 80;\
root /app/web;\
server_name reporting;\
\
location / {\
try_files $uri /app_dev.php$is_args$args;\
}\
\
location ~ [^/]\.php(/|$) {\
fastcgi_pass php_1:9000;\
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;\
# regex to split $uri to $fastcgi_script_name and $fastcgi_path\
fastcgi_split_path_info ^(.+\.php)(/.+)$;\
# Check that the PHP script exists before passing it\
try_files $fastcgi_script_name =404;\
# Bypass the fact that try_files resets $fastcgi_path_info\
# # see: http://trac.nginx.org/nginx/ticket/321\
set $path_info $fastcgi_path_info;\
fastcgi_param PATH_INFO $path_info;\
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;\
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\
fastcgi_param HTTPS on;\
fastcgi_param HTTP_SCHEME https;\
include fastcgi_params;\
fastcgi_index index.php;\
autoindex off;\
access_log /var/log/nginx/access.log;\
error_log /var/log/nginx/error.log;\
}\
}' > /etc/nginx/sites-available/reporting.conf
RUN ln -s /etc/nginx/sites-available/reporting.conf /etc/nginx/sites-
enabled/reporting.conf
RUN unlink /etc/nginx/sites-enabled/default
RUN mkdir -p /app/web
RUN echo '<?php phpinfo() ?>' > /app/web/app_dev.php
RUN sed -i 's/worker_processes\sauto;/worker_processes 1;/'
/etc/nginx/nginx.conf
RUN cat /etc/nginx/nginx.conf
WORKDIR /etc/nginx
EXPOSE 80
EXPOSE 443
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
STOPSIGNAL SIGTERM
CMD ["nginx", "-g", "daemon off;"]
我的php fpm Dockerfile
FROM debian:stretch
RUN apt-get update && apt-get install -y wget gnupg2 net-tools
RUN echo 'deb http://packages.dotdeb.org stable all' >>
/etc/apt/sources.list
RUN echo 'deb-src http://packages.dotdeb.org stable all' >>
/etc/apt/sources.list
RUN wget https://www.dotdeb.org/dotdeb.gpg
RUN apt-key add dotdeb.gpg
RUN apt-get update && apt-get install -y --no-install-recommends php7.0
php7.0-fpm php7.0-mysql php7.0-curl php7.0-json php7.0-gd php7.0-crypt
php7.0-msgpack php7.0-memcached php7.0-intl php7.0-sqlite3 php7.0-gmp
php7.0-geoip php7.0-mbstring php7.0-redis php7.0-xml php7.0-zip
RUN sed -i 's/\/run\/php\/php7.0-fpm.sock/127.0.0.1:9000/g'
/etc/php/7.0/fpm/pool.d/www.conf
RUN sed -i "s/;daemonize\s*=\s*yes/daemonize = no/g"
/etc/php/7.0/fpm/php-fpm.conf
EXPOSE 9000
RUN mkdir -p /app/web
RUN echo '<?php phpinfo()?>' > /app/web/app_dev.php
RUN service php7.0-fpm start
ENTRYPOINT /usr/sbin/php-fpm7.0 --nodaemonize
我认为,php-fpm conf中缺少某些配置,但我没有找到任何内容: - /
一些帮助将不胜感激:)