Docker和nginx的新功能在此级别设置。有问题让nginx与php容器交谈。在导航时继续获取502 Bad Gateway
,并且来自docker的错误如下:
web | 2018/03/21 09:25:40 [error] 6#6: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: web, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.4:9000", host: "localhost:8080"
web | 172.18.0.1 - - [21/Mar/2018:09:25:40 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36" "-"
web | 2018/03/21 09:25:40 [error] 6#6: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: web, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://172.18.0.4:9000", host: "localhost:8080", referrer: "http://localhost:8080/"
web | 172.18.0.1 - - [21/Mar/2018:09:25:40 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36" "-"
我的nginx conf:
server {
listen 80;
# listen 443 ssl;
server_name web;
charset utf-8;
client_max_body_size 10M;
root /usr/share/nginx/html/public;
index index.php index.html index.htm;
location / {
# try to serve file directly, fallback to rewrite
# see laravel docs On Nginx, the following directive in your site configuration will allow "pretty" URLs:
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/.+\.php(/|$) {
include fastcgi_params;
fastcgi_pass php:9000;
fastcgi_param DB_HOST mariadb:33061;
fastcgi_param DB_DATABASE homestead;
fastcgi_param DEFAULT_HOME_URL $http_host;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 4 16k;
fastcgi_buffer_size 32k;
fastcgi_busy_buffers_size 32k;
}
}
我的码头工人组成了yaml:
version: '3'
services:
web:
container_name: web
build:
context: ./nginx
restart: always
volumes:
- "./nginx/insight.conf:/etc/nginx/conf.d/default.conf"
- "/Users/lokisinclair/Projects/nps:/usr/share/nginx/html"
ports:
- "8080:80"
links:
- php
- mariadb
mailcatcher:
container_name: mailcatcher
image: yappabe/mailcatcher
ports:
- 1025:1025
- 1080:1080
php:
container_name: php
build:
context: ./php
restart: always
volumes:
- "/Users/lokisinclair/Projects/nps:/usr/share/nginx/html"
ports:
- "9000:9000" # PHP
- "5000:5000" # ProcessTags.py
links:
- mariadb
- mailcatcher
environment:
- DB_HOST=mariadb
- DB_USER=homestead
- DB_PASS=secret
mariadb:
container_name: db
image: mariadb
ports:
- "33061:3306"
restart: always
volumes:
- "./database:/var/lib/mysql"
- "./mariadb:/tmp"
command: mysqld --init-file="/tmp/init.sql"
environment:
- MYSQL_DATABASE=homestead
- MYSQL_USER=homestead
- MYSQL_PASSWORD=secret
我尝试使用各种指南多次重写nginx .conf,但它总是以[XYZ] is not allowed here in...
回复 - 这并不过分有用。这个conf工作,但只是无法访问php容器。请问有人可以解决一些问题吗?
更新 我已经在Web容器上安装了telnet并试图访问端口9000,但它也在命令行中被拒绝。
php dockerfile
FROM php:7.0.0-fpm
LABEL maintainer="<REMOVED>"
RUN apt-get update && apt-get upgrade -y \
g++ \
libc-client-dev \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libkrb5-dev \
libpq-dev \
libmagickwand-dev \
libmcrypt-dev \
libpng-dev \
libmemcached-dev \
libssl-dev \
libssl-doc \
libsasl2-dev \
zlib1g-dev \
python3.4 \
python-pip \
libmysqlclient-dev \
python-dev \
procps \
&& docker-php-ext-install \
bz2 \
iconv \
mbstring \
mysqli \
pgsql \
pdo_mysql \
pdo_pgsql \
soap \
zip \
&& docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl \
&& docker-php-ext-install sockets \
&& yes '' | pecl install imagick && docker-php-ext-enable imagick \
&& docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
&& docker-php-ext-install imap \
&& pecl install memcached && docker-php-ext-enable memcached \
&& pecl install mongodb && docker-php-ext-enable mongodb \
&& pecl install redis && docker-php-ext-enable redis \
&& pecl install xdebug && docker-php-ext-enable xdebug \
&& apt-get autoremove -y --purge \
&& apt-get clean \
&& rm -Rf /tmp/* \
&& pip install nltk \
&& pip install MySQL-python
# Grab python NLTK libs
RUN python -m nltk.downloader -d /usr/local/share/nltk_data all
# Set working directory to root of Insight
WORKDIR "/usr/share/nginx/html"
ADD init.sh /tmp/init.sh
CMD chmod +x /tmp/init.sh
CMD /bin/bash /tmp/init.sh
# Expose network ports
EXPOSE 5000
EXPOSE 9000