Proxying react app using nginx on docker-compose - reactjs

I am trying to use docker-compose to run 2 containers - a sample react app and an nginx to behave as reverse-proxy.
I've ran npx create-react-app react-app to create the first container, and added the following Dockerfile to the folder -
FROM node
RUN yarn global add serve
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn
COPY . ./
RUN yarn build
CMD serve -s build
I've then proceeded to create the following nginx configuration file under ./nginx -
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /react {
proxy_pass http://react:5000;
}
}
Finally, I've created this docker-compose.yaml file in the root of the project -
version: '3'
services:
nginx:
image: nginx:latest
container_name: production_nginx
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- 80:80
- 443:443
react:
build: ./react-app
container_name: react-app
expose:
- "5000"
ports:
- 5000:5000
I then use docker-compose up --build to launch my stack, but when I use the http://localhost/react path I get the following errors in my nginx access logs -
eact-app | INFO: Accepting connections at http://localhost:5000
production_nginx | 172.18.0.1 - - [29/Jan/2020:18:24:29 +0000] "GET /react HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
production_nginx | 2020/01/29 18:24:29 [error] 7#7: *1 open() "/usr/share/nginx/html/static/css/main.d1b05096.chunk.css" failed (2: No such file or directory), client: 172.18.0.1, server: localhost, request: "GET /static/css/main.d1b05096.chunk.css HTTP/1.1", host: "localhost", referrer: "http://localhost/react"
production_nginx | 172.18.0.1 - - [29/Jan/2020:18:24:29 +0000] "GET /static/css/main.d1b05096.chunk.css HTTP/1.1" 404 555 "http://localhost/react" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
production_nginx | 172.18.0.1 - - [29/Jan/2020:18:24:29 +0000] "GET /static/js/2.250dc4af.chunk.js HTTP/1.1" 404 555 "http://localhost/react" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
production_nginx | 172.18.0.1 - - [29/Jan/2020:18:24:29 +0000] "GET /static/js/main.de4c6317.chunk.js HTTP/1.1" 404 555 "http://localhost/react" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
production_nginx | 2020/01/29 18:24:29 [error] 7#7: *4 open() "/usr/share/nginx/html/static/js/2.250dc4af.chunk.js" failed (2: No such file or directory), client: 172.18.0.1, server: localhost, request: "GET /static/js/2.250dc4af.chunk.js HTTP/1.1", host: "localhost", referrer: "http://localhost/react"
production_nginx | 2020/01/29 18:24:29 [error] 7#7: *3 open() "/usr/share/nginx/html/static/js/main.de4c6317.chunk.js" failed (2: No such file or directory), client: 172.18.0.1, server: localhost, request: "GET /static/js/main.de4c6317.chunk.js HTTP/1.1", host: "localhost", referrer: "http://localhost/react"
production_nginx | 2020/01/29 18:24:29 [error] 7#7: *5 open() "/usr/share/nginx/html/manifest.json" failed (2: No such file or directory), client: 172.18.0.1, server: localhost, request: "GET /manifest.json HTTP/1.1", host: "localhost", referrer: "http://localhost/react"
production_nginx | 172.18.0.1 - - [29/Jan/2020:18:24:29 +0000] "GET /manifest.json HTTP/1.1" 404 555 "http://localhost/react" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
production_nginx | 2020/01/29 18:24:34 [error] 7#7: *3 open() "/usr/share/nginx/html/static/js/2.250dc4af.chunk.js" failed (2: No such file or directory), client: 172.18.0.1, server: localhost, request: "GET /static/js/2.250dc4af.chunk.js HTTP/1.1", host: "localhost", referrer: "http://localhost/react"
production_nginx | 172.18.0.1 - - [29/Jan/2020:18:24:34 +0000] "GET /static/js/2.250dc4af.chunk.js HTTP/1.1" 404 555 "http://localhost/react" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
production_nginx | 172.18.0.1 - - [29/Jan/2020:18:24:34 +0000] "GET /static/js/main.de4c6317.chunk.js HTTP/1.1" 404 555 "http://localhost/react" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
production_nginx | 2020/01/29 18:24:34 [error] 7#7: *4 open() "/usr/share/nginx/html/static/js/main.de4c6317.chunk.js" failed (2: No such file or directory), client: 172.18.0.1, server: localhost, request: "GET /static/js/main.de4c6317.chunk.js HTTP/1.1", host: "localhost", referrer: "http://localhost/react"
It seems to me like nginx is looking for Reacts static assets in the nginx container, but I'm not sure why doesn't it proxy these requests over to the react container. Any idea how to solve this?

I haven't used nginx to reverse proxy to my front end. Only to connect requests from my front end to my server. Instead, you might try hosting your react-app directly through nginx. Here is one way that I have done this.
Instead of running two containers, I set up a Dockerfile in the root of my react-app. The Dockerfile does a production build of the react app and then copies it into nginx to be hosted at the / route in your nginx configuration. This is what that file looks like.
# Frontend build based on Node.js
FROM node:11.12.0-alpine as build-stage
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install react-scripts#latest -g
COPY . /usr/src/app
#RUN CI=true npm test
RUN npm run build
# Stage 1
# Production build based on Nginx with artifacts from Stage 0
FROM nginx:1.15.9-alpine
COPY config/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build-stage /usr/src/app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
In the root of the react-app I also have a config directory. Inside that directory I have nginx.conf file which looks like this.
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}
# redirect server error pages
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Since the frontend build is copied into nginx in the first step, it can now find the build directory inside it's own file system. After that, you can build and run the image in a container and everything should build properly. I think all you would have to do at that point is move your docker-compose.yml file into the react-app root, get rid of the react service, change image: nginx:latest to build: . and run docker-compose up -d. You could also forgo compose and just use docker by running docker build -t react-app and after that builds, run docker run -d -p 80:80 react-app in the root of the react-app directory. This is a very simple way to get started and perhaps not quite what you were looking for. Hope it helps though.

After finding this great blogpost I managed to solve the issue by changing the nginx configuration to this -
upstream backend {
server react:5000;
}
server {
listen 80;
server_name localhost§
root /usr/src/app;
location / {
try_files $uri #backend;
}
location #backend {
proxy_pass http://backend;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Following is necessary for Websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

Related

How to serve two react applications with nginx and docker ? Getting 111: Connection refused and 502 Bad Gateway

There are 4 docker containers running in mac os.
frontend app container at Port: 3000
frontend_admin app container at Port: 3001
backend app container at Port: 5055
nginx container at Port: 80
First I configured nginx for the frontend app and backend app. It worked well. Then I configured frontend_admin app (at Port: 3001). I want to redirect user to frontend_admin app when the url contains /admin i.e. http://localhost/admin.
So I configured nginx like below.
# Cache zone
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;
upstream frontend {
# server localhost:3000;
# Container name
server frontend:3000;
}
upstream frontend_admin {
# server localhost:3001;
# Container name
server frontend_admin:3001;
}
upstream backend {
# server localhost:5055;
# Container name
server backend:5055;
}
server {
listen 80 default_server;
server_name _;
server_tokens off;
gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css application/javascript image/svg+xml;
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;
# To serve backend
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
# change localhost -> backend when you run in mac
proxy_pass http://backend/api;
proxy_redirect off;
client_max_body_size 20m;
client_body_buffer_size 256k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
}
# BUILT ASSETS (E.G. JS BUNDLES)
# Browser cache - max cache headers from Next.js as build id in url
# Server cache - valid forever (cleared after cache "inactive" period)
# frontend app
location /_next/static {
proxy_cache STATIC;
proxy_pass http://frontend;
}
# STATIC ASSETS (E.G. IMAGES)
# Browser cache - "no-cache" headers from Next.js as no build id in url
# Server cache - refresh regularly in case of changes
# frontend app
location /static {
proxy_cache STATIC;
proxy_ignore_headers Cache-Control;
proxy_cache_valid 60m;
proxy_pass http://frontend;
}
# DYNAMIC ASSETS - NO CACHE
# frontend app
location / {
proxy_pass http://frontend;
}
# DYNAMIC ASSETS - NO CACHE
# to redirect to frontend_admin app
location /admin {
rewrite /admin/(.*) /$1 break;
proxy_pass http://frontend_admin;
proxy_redirect off;
proxy_set_header Host $host;
}
}
After this I am getting below error in nginx logs.
2022/11/20 10:33:58 [error] 30#30: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.23.0.1, server: _, request: "GET /admin HTTP/1.1", upstream: "http://127.0.0.1:3001/admin", host: "localhost"
172.23.0.1 - - [20/Nov/2022:10:33:58 +0000] "GET /admin HTTP/1.1" 502 552 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" "-"
2022/11/20 10:33:58 [error] 30#30: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.23.0.1, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3000/favicon.ico", host: "localhost", referrer: "http://localhost/admin"
172.23.0.1 - - [20/Nov/2022:10:33:58 +0000] "GET /favicon.ico HTTP/1.1" 502 552 "http://localhost/admin" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" "-"
When I put http://localhost:3001 in browser the frontend_admin app is working well. But when I put http://localhost/admin I am getting above error logs in nginx and browser shows 502 Bad Gateway
logs in frontend_admin container
> frontend-admin#0.1.0 start
> PORT=3001 react-scripts --openssl-legacy-provider start
ℹ 「wds」: Project is running at http://172.23.0.3/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /app/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
Compiled successfully!
You can now view frontend-admin in the browser.
Local: http://localhost:3001
On Your Network: http://172.23.0.3:3001
Note that the development build is not optimized.
To create a production build, use npm run build.
Is this way possible or am I doing something wrong to connect two front end apps with nginx and docker ? If that is the case what will be the correct way ?
Thank you.
Edit
I have updated nginx upstream servers (replaced localhost with container name) based on #David comment.
Then I am getting this error in my browser console for http://localhost/admin
Edit 2

React Nginx Proxy Pass every file loading index.html

I've been scouring trying to find a solution, but when I go to my domain, all my static files are just returning index.html, giving me a
Uncaught SyntaxError: Unexpected token '<' error
My setup is this:
A server that runs nginx for multiple domains, with the one site in question having the following config file
server {
listen 80;
listen [::]:80;
server_name domain.com www.domain.com;
return 302 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/ssl/domain/cert.pem;
ssl_certificate_key /etc/ssl/domain/key.pem;
server_name domain.com www.domain.com;
location / {
proxy_pass http://10.0.0.41:80;
}
location /api {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.0.0.41:3000;
where 10.0.0.41 is another server which is hosting 2 docker containers, one for my react app/nginx and one for my express backend app.
The reverse proxy to the express app works perfect, but when I try to visit domain.com, my js files are returning as index.html and not loading, giving me the error above.
When I visit 10.0.0.41 in my browser, everything loads as it should and works correctly, just not when coming from the domain.
this is the nginx config file for the second server
server {
listen 80;
listen [::]:80;
root /usr/share/nginx/html;
location / {
try_files $uri /index.html;
}
location ~ .(static)/(js|css|media)/(.+)$ {
try_files $uri $uri/ /$1/$2/$3;
}
}
I've tried everything I can find, adding that last line in the 2nd nginx config, removing, adding, changing homepage in package.json.
I am using React router, with <Route exact path="/"
This has been driving me crazy and any help would be greatly appreciated, and if I left out any important information let me know.
Difference in requests:
10.0.0.41:80
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET / HTTP/1.1" 200 644 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET /static/css/main.69847ccd.css HTTP/1.1" 200 2261 "http://10.0.0.41/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET /static/js/main.10f72de5.js HTTP/1.1" 200 514201 "http://10.0.0.41/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET /static/js/423.0a0d8ebb.chunk.js HTTP/1.1" 200 3280 "http://10.0.0.41/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
10.0.0.142 - - [02/Aug/2022:13:42:53 +0000] "GET /favicon.ico HTTP/1.1" 200 3150 "http://10.0.0.41/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "-"
www.domain.com
10.0.0.101 - - [02/Aug/2022:13:44:37 +0000] "GET / HTTP/1.1" 200 644 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "my_ip, cloudflare_ip"
10.0.0.101 - - [02/Aug/2022:13:44:37 +0000] "GET /manifest.json HTTP/1.1" 304 0 "https://www.my_domain.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" "my_ip, cloudflare_ip"
10.0.0.142 is the machine i'm testing with, 10.0.0.101 is the first nginx server

502 Bad Gateway error while opening a dockerized react app

I have a multi-container docker app in React that uses Nginx as a server. When I try to open it in the browser I get 502 Bad Gateway error with a message:
2021/12/30 11:58:44 [error] 31#31: *31 connect() failed (111: Connection refused) while connecting to upstream, client: 172.23.0.1, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.23.0.2:3000/favicon.ico", host: "localhost:3050", referrer: "http://localhost:3050/"
Here is nxing config file:
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;
}
}
Here's the fragment of docker-compose for Nginx:
nginx:
depends_on:
- api
- client
restart: always
build:
dockerfile: Dockerfile.dev
context: ./nginx
ports:
- '3050:80'
How can I fix this?
Thank you for posting this question, it helped me.
Also, in docker-compose.yml file inside the root directory. I had to add stdin_open: true,
client:
stdin_open: true
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- /app/node_modules
- ./client:/app

Request to api server(Golang) via nginx failed and returned 404 error

I'm setting up nginx in docker environment.
When I try to access to api server via nginx port, request returns 404 error.
Here is the stack.
・client: react/axios
・api: golang/gin
・web server: nginx
・db: mysql
・container: docker
・ci-tool: travis
・deploy: aws elastic beanstalk
Entire source code is here:
https://github.com/jpskgc/article
article
├ client
│ └ nginx
│ └ default.conf
├ api
├ nginx
│ └ default.conf
└ docker-compose.yml
Here is docker-compose.yml.
//docker-compose.yml
version: '3'
services:
nginx:
restart: always
build:
dockerfile: Dockerfile.dev
context: ./nginx
ports:
- '3050:80'
depends_on:
- client
- api
api:
build:
dockerfile: Dockerfile.dev
context: ./api
volumes:
- ./api:/app
depends_on:
- db
tty: true
environment:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- MYSQL_USER
- MYSQL_PASSWORD
- MYSQL_HOST
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- /app/node_modules
- ./client:/app
Here is default.conf.
//default.conf
upstream client {
server client:3000;
}
upstream api {
server api:2345;
}
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;
}
}
Also there is default.conf in client.
server {
listen 3000;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
I expect nginx reverse proxy to port 2345 api server.
But the actual returns 404 response.
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:06 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:06 +0000] "GET /static/js/bundle.js HTTP/1.1" 304 0 "http://localhost:3050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:07 +0000] "GET /static/js/0.chunk.js HTTP/1.1" 304 0 "http://localhost:3050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:07 +0000] "GET /static/js/main.chunk.js HTTP/1.1" 304 0 "http://localhost:3050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:07 +0000] "GET /static/js/bundle.js.map HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:08 +0000] "GET /static/js/0.chunk.js.map HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:08 +0000] "GET /static/js/main.chunk.js.map HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
api_1 | [GIN] 2019/08/09 - 22:19:09 | 404 | 41.937µs | 172.23.0.5 | GET /articles
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:09 +0000] "GET /api/articles HTTP/1.1" 404 18 "http://localhost:3050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:10 +0000] "GET /sockjs-node/info?t=1565389150444 HTTP/1.1" 200 90 "http://localhost:3050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
nginx_1 | 172.23.0.1 - - [09/Aug/2019:22:19:10 +0000] "GET /manifest.json HTTP/1.1" 304 0 "http://localhost:3050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36" "-"
Also when accessing to actual deployed url, it returns 502 Bad Gateway now.
http://multidocker-env.vwnrixavuv.ap-northeast-1.elasticbeanstalk.com/api/articles
As Enix suggested on comment, after removing rewrite directive, issue is resolved.
rewrite /api/(.*) /$1 break;

node http-server stops with exception when using proxy Error: connect EHOSTUNREACH

I'm using node package http-server to serve my web pages locally. Suddenly it started failing to connect to the proxy server. Searched in stackoverflow but didn't get satisfied answer for this scenario. Please help.
Here are the commands and logs:
http-server -p 8000 app/ --proxy localhost:3000
Starting up http-server, serving app/
Available on:
http:127.0.0.1:8000
http:192.168.1.6:8000
Unhandled requests will be served from: localhost:3000
Hit CTRL-C to stop the server
[Mon, 04 Jul 2016 13:29:27 GMT] "POST /candidates/resumes"
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
/Users/tushar/.node_modules_global/lib/node_modules/http-server/node_modules/http-proxy/lib/http-proxy/index.js:119
throw err;
^
Error: connect EHOSTUNREACH 0.0.11.184:80 - Local (192.168.1.6:58636)
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at connect (net.js:843:14)
at net.js:985:7
at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:63:16)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:82:10)
Found the issue. My bad. The proxy address has to be inside the quotation mark. No idea when it has become mandatory to be quoted. Here is the example command if it helps anyone -
http-server app/ -p 8000 --proxy 'http://localhost:3000'
or simply the following (default port and current-dir instead of specifying a folder 'app')
http-server --proxy 'http://localhost:3000'

Resources