Score:0

502 Bad Gateway with NuxtJS and NGINX Proxy Companion

cn flag

I'm trying to setup a proxy with NGINX proxy companion but I'm facing with a 502 Bad Gateway error...

Here is my docker-compose.yml:

  nuxtjs:
    build:
      context: .
      dockerfile: docker/nuxtjs/Dockerfile
    environment:
      API_BASE_URL: fff.com
      VIRTUAL_HOST: fff.com
      LETSENCRYPT_HOST: fff.com
    ports:
      - "8000:80"
    container_name: ${NUXTJS_CONTAINER_NAME}
    volumes:
      - ./front:/usr/src/app/
      - /usr/src/app/node_modules

Dockerfile :

FROM node:lts

# create destination directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# copy the app, note .dockerignore
COPY ./front /usr/src/app
RUN yarn

# build necessary, even if no static files are needed,
# since it builds the server as well
RUN yarn build

# expose 80 on container
EXPOSE 80

# set app serving to permissive / assigned
ENV NUXT_HOST=0.0.0.0
# set app port
ENV NUXT_PORT=80

# start the app
CMD [ "yarn", "dev" ]

And the proxy show this in logs:

*40 no live upstreams while connecting to upstream, client: myip, server: fff.com, request: "GET /favicon.ico HTTP/2.0", upstream: "http://fff.com-upstream/favicon.ico", host: "xxx.com", referrer: "https://fff.com/"

And the conf generated:

upstream fff.com {
        # Cannot connect to network 'webproxy' of this container
        # Fallback entry
        server 127.0.0.1 down;
}
server {
        server_name fff.com;
        listen 80 ;
        access_log /var/log/nginx/access.log vhost;
        # Do not HTTPS redirect Let'sEncrypt ACME challenge
        location ^~ /.well-known/acme-challenge/ {
                auth_basic off;
                auth_request off;
                allow all;
                root /usr/share/nginx/html;
                try_files $uri =404;
                break;
        }
        location / {
                return 301 https://$host$request_uri;
        }
}
server {
        server_name fff.com;
        listen 443 ssl http2 ;
        access_log /var/log/nginx/access.log vhost;
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:50m;
        ssl_session_tickets off;
        ssl_certificate /etc/nginx/certs/fff.com.crt;
        ssl_certificate_key /etc/nginx/certs/fff.com.key;
        ssl_dhparam /etc/nginx/certs/fff.com.dhparam.pem;
        ssl_stapling on;
        ssl_stapling_verify on;
        ssl_trusted_certificate /etc/nginx/certs/fff.com.chain.pem;
        add_header Strict-Transport-Security "max-age=31536000" always;
        include /etc/nginx/vhost.d/default;
        location / {
                proxy_pass http://fff.com;
        }
}

Does anyone have an idea?

thanks

Michael Hampton avatar
cz flag
What is `fff.com-upstream`?
FindL avatar
cn flag
Honestly, I don't know, it has been generated by nginx-companion in think
Score:0
cn flag

Solved: I forgot to attach the proxy to the webproxy network....

Score:0
in flag

Your ports definition is wrong. You are mapping the port 80 from the container to port 8000 on the host, but your container exposes port 8000.

ports:
  - "80:8000"

Or, if you want to keep port 8000:

ports:
  - "8000"
FindL avatar
cn flag
I just edited the Dockerfile to expose 80 on the container Still not working :/ Same error
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.