Quasar SSR app in docker container: connection refused

  • Hi!
    I am confused. My quasar app is built in ssr mode and put in a docker container. It works fine locally, but when I start it on server - nginx shows bad gateway 502. Please help me to understand what am I doing wrong.
    here is docker-compose:

      image: nginx:1.17-alpine
      container_name: webserver
      restart: unless-stopped
      tty: true
        - "80:80"
        - "443:443"
        - ./:/var/www
        - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf
        - /root/.acme.sh/amenu.ru:/etc/acme.sh/amenu.ru
        - /etc/conf.ddhparam.pem:/etc/nginx/conf.ddhparam.pem
        - front
        - app-network
        - front
        context: ./myapp/
        dockerfile: Dockerfile
      container_name: front
      restart: unless-stopped
      tty: true
        - "4000:3000"
        - app-network


    FROM node:14-alpine as build-stage
    WORKDIR /app
    COPY package*.json ./
    RUN npm install && npm install -g @quasar/cli
    COPY . .
    RUN quasar build -m ssr
    # этап production (production-stage)
    FROM node:14-alpine as production-stage
    WORKDIR /usr/share/www
    COPY --from=build-stage /app/dist/ssr ./
    RUN npm install
    EXPOSE 3000
    CMD ["node", "index.js"]


    #user www-data;
    pid /run/nginx.pid;
    worker_processes auto;
    worker_rlimit_nofile 65535;
    events {
    	multi_accept on;
    	worker_connections 65535;
    http {
    	charset utf-8;
    	sendfile on;
    	tcp_nopush on;
    	tcp_nodelay on;
    	server_tokens off;
    	log_not_found off;
    	types_hash_max_size 2048;
    	client_max_body_size 16M;
    	# MIME
    	include mime.types;
    	default_type application/octet-stream;
    	# logging
    	access_log /var/log/nginx/access.log;
    	error_log /var/log/nginx/error.log warn;
    	server {
    		listen 80;
    		server_name .amenu.ru;
    		location / {
    			proxy_pass http://front:4000;
    			proxy_http_version 1.1;
    			proxy_set_header Upgrade $http_upgrade;
    			proxy_set_header Connection 'upgrade';
    			proxy_set_header Host $host;
    			proxy_cache_bypass $http_upgrade;

    nginx log:

    *1 connect() failed (111: Connection refused) while connecting to upstream, client:, server: example.com, request: "GET /auth HTTP/1.1", upstream: "", host: "example.com" - - [22/May/2020:09:40:23 +0000] "GET /auth HTTP/1.1" 502 150 "-" "....."

  • Found it. It was a stupid mistake but it cost me a few hours of research. So here it is: nginx proxy_pass http://front:4000; should be proxy_pass http://front:3000; instead.
    Which means that althow docker exposes port 4000 OUTSIDE it still maps to 3000 inside docker’s app-network. Counter intuitive to me. 😕

  • Hi @Boris ,
    I use Lando for my dev docker and it works fine but when i reload my page in browser i get Error: connect ECONNREFUSED

    I think this is a SSR problem. any idea how to solve this?

    Bers regards
    /Peter Sweden

Log in to reply