Nginx problem with Elastic Beanstalk

Hi, I want to deploy my multi-container application to Elastic Beanstalk. My project contains 3 images: client, api, and nginx. Client is a NextJS app (which works fine), API is an express typescript app, and nginx contains a default.conf file which redirects every request to /api to the express app. This is so that I can differentiate the client and the api.

For example:

– route – /user gets redirected to the client’s /user

– route – /api/user gets redirected to the api’s /user

This works perfectly fine on localhost, but once I deploy it, while I’m able to view my client assets, the API returns a status of 502 saying it’s not found. I checked Elastic Container Service, and it shows that the API container did not return a status of 1 and is running perfectly fine. I’m wondering if this has anything to do with my production API dockerfile.

Here’s default.conf:

upstream client { server client:3000; } upstream api { server api:5000; } server { listen 80; location / { proxy_pass http://client; } location /sockjs-node { proxy_pass http://client; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } location /api { rewrite /api/(.*) /$1 break; proxy_pass http://api; } } 

My API Dockerfile:

FROM node:alpine WORKDIR /usr/local/app COPY ./package*.json ./ RUN npm install COPY . . ENV NODE_ENV=production RUN npm run build // the command is tsc, build config comes from tsconfig.json which should be copied in the step COPY . . CMD npm run start // the command is "node build/app.js" 

My nginx Dockerfile:

FROM nginx COPY ./default.conf /etc/nginx/conf.d/default.conf 

I’ve integrated travis CI and created a to push my images to Docker hub. I then created a file which has contains the 3 container definitions and pulls the images from Dockerhub. Here is the file:

{ "AWSEBDockerrunVersion": 2, "containerDefinitions": [ { "name": "client", "image": "skullcutter02/hourglass-client", "hostname": "client", "essential": false, "memory": 128 }, { "name": "api", "image": "skullcutter02/hourglass-api", "hostname": "api", "essential": false, "memory": 256 }, { "name": "nginx", "image": "skullcutter02/hourglass-nginx", "hostname": "nginx", "essential": true, "portMappings": [{ "hostPort": 80, "containerPort": 80 }], "links": ["client", "api"], "memory": 128 } ] } 

Thanks for reading!

submitted by /u/fungigamer
[link] [comments]