Docker for mac,nginx:连接到上游时没有实时上游

时间:2018-03-24 21:03:09

标签: node.js docker nginx docker-for-mac

下面的配置在Ubuntu上运行正常,但在使用Docker for Mac的Mac OSX上没有。

我有一个后端应用程序(PHP / Symfony)和一个前端应用程序(NodeJs / Angular2) 后端在MacOSX上工作正常。 但不是前端,Nginx说502和

no live upstreams while connecting to upstream

在日志中。

docker-compose.yml

version: '2'

services:
    web-server:
        build: web-server
        container_name: mysite_web_server
        ports:
            - 80:80
            - 443:443
            - 3010:3010
        volumes:
            - ${BACKEND_PATH}:/var/www/backend
            - ${FRONTEND_PATH}:/var/www/frontend
            - ${GATEWAY_PATH}:/var/www/gateway


    db:
        image: mysql/mysql-server:5.6
        container_name: mysite_db
        volumes:
            - ./.data/db:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
            MYSQL_DATABASE: ${MYSQL_DATABASE}
            MYSQL_USER: ${MYSQL_USER}
            MYSQL_PASSWORD: ${MYSQL_PASSWORD}

    redis:
        image: redis:alpine
        container_name: mysite_redis
        ports:
            - 6379:6379

请参阅nginx中的 mysite.conf

server {
    listen       80;
    server_name  mysite.lo;
    return       301 http://www.mysite.lo$request_uri;
}

server {
    listen 80;
    server_name www.mysite.lo;

    access_log /var/log/nginx/frontend.access.log;
    error_log /var/log/nginx/frontend.error.log;

    location / {
         proxy_pass http://localhost:8083;
    }
}

Supervisor管理所有服务:

[supervisord]
nodaemon=true

[program:php-fpm]
command=/usr/sbin/php-fpm7.0 -F
autostart=true
autorestart=unexpected
stdout_logfile=/var/log/supervisor/php-fpm.log
stdout_logfile_maxbytes=0
stderr_logfile=/var/log/supervisor/php-fpm.err.log
stderr_logfile_maxbytes=0
exitcodes=0

[program:nginx]
command=nginx -c /etc/nginx/nginx.conf  -g 'daemon off;'
process_name=nginx
numprocs=1
autostart=true
autorestart=unexpected
startsecs=0
stdout_logfile=/var/log/supervisor/nginx.log
stdout_logfile_maxbytes=0
stderr_logfile=/var/log/supervisor/nginx.err.log
stderr_logfile_maxbytes=0

[program:frontend_start]
environment=PORT=8083
command=sh -c "cd /var/www/frontend && /usr/bin/npm run start"
process_name=frontend_start
user=root
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/frontend_start.err.log
stdout_logfile=/var/log/supervisor/frontend_start.log
startsecs=0
stopasgroup=true

[program:frontend_watch] 
environment=PORT=8083
command=sh -c "sleep 3; if [ ! -f 
/var/www/frontend/dist/server/index.js ]; then exit 0; fi; cd 
/var/www/frontend && /usr/bin/npm run watch"
process_name=frontend_watch
user=root
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/frontend_watch.err.log
stdout_logfile=/var/log/supervisor/frontend_watch.log
startsecs=0
stopasgroup=true

修改 我为Web服务器和主管添加了Dockerfile

FROM ubuntu:16.04

ENV TZ 'Europe/Paris'

RUN apt-get update && apt-get install -y \
    apt-utils \
    language-pack-en-base \
    dbus \
    tzdata \
    curl \
    vim \
    less \
    acl \
    wget \
    supervisor \
    mysql-client \
    software-properties-common

RUN mkdir -p /var/log/supervisor
COPY supervisor/web-server.conf /etc/supervisor/conf.d/web-server.conf


RUN mkdir -p /root/messageApi
ADD message-api/messageApiServer /root/messageApi/messageApiServer

RUN chmod +x /root/messageApi/messageApiServer
ADD /message-api/config.json /root/messageApi/config.json

RUN ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
RUN apt-get update && apt-get install -y ntp

################
# Web server
RUN add-apt-repository ppa:nginx/stable -y
RUN apt-get update && apt-get install -y \
    nginx \
    nginx-extras

ADD nginx/nginx.conf /etc/nginx/
ADD nginx/site.conf /etc/nginx/sites-available/
ADD nginx/gateway.conf /etc/nginx/sites-available/

RUN ln -s /etc/nginx/sites-available/site.conf /etc/nginx/sites-enabled/site.conf
RUN ln -s /etc/nginx/sites-available/gateway.conf /etc/nginx/sites-enabled/gateway.conf
RUN rm /etc/nginx/sites-enabled/default && rm /etc/nginx/sites-available/default

RUN usermod -u 1000 www-data

EXPOSE 80
EXPOSE 443
EXPOSE 3010

RUN service nginx restart
# Web server
################

###############
# mysql
RUN apt-get install -y mysql-client
# mysql
################

################
# php 7.0
RUN LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php -y

RUN apt-get update && apt-get install -y \
    php7.0-cli \
    php7.0-fpm \
    php7.0 \
    php7.0-mysql \
    php7.0-intl \
    php7.0-curl \
    php7.0-redis \
    php7.0-gd \
    php7.0-xml \
    php7.0-zip \
    php7.0-mbstring \
    php-apcu \
    php-imagick

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-    dir=/usr/local/bin --filename=composer
RUN composer --version

RUN /bin/sed -i 's/memory_limit = [^ ]*/memory_limit = -1/g'     /etc/php/7.0/cli/php.ini
RUN service php7.0-fpm start

# php 7.0
###############

###############
# Node
RUN NODE_VERSION=9.8.0 \
    && wget https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz \
    && tar zxf node-v${NODE_VERSION}-linux-x64.tar.gz \
    && cd node-v${NODE_VERSION}-linux-x64 \
    && cp -r bin/* /usr/local/bin/. \
    && cp -r include/* /usr/local/include/. \
    && cp -r share/* /usr/local/share/.

RUN apt-get -qq -y --assume-yes install npm && npm i -g typescript
# Node
###############

###############
# Postfix
RUN DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' -f -q -y install postfix mailutils mutt
# Postfix
###############

# Keeping up
CMD ["/usr/bin/supervisord"]

0 个答案:

没有答案