0

I am using docker-compose for deploying Nodejs(KeystoneJS) app. I want to access a static png by the url like: http://localhost:3000/uploads/apks/5e1ac55962c6a800230d67fb-test.png Right now I got 404 error.

There are 3 containers, Nginx, app, mongo.

Folder structre

  • apks
  • myapp
    • Dockfile
    • docker-compose.yml

Here is my structure:

enter image description here

  • The images are under apks
  • Set set static alias in Nginx config file to docker app container folder: /home/node/static/apks/

default.conf

upstream my_app {
  server 192.168.1.119:3000;
}

server {
        listen *:80;
        listen [::]:80;       

        listen 443 ssl;
        ssl_certificate /etc/nginx/certs/server-cert.pem;
        ssl_certificate_key /etc/nginx/certs/server-key.pem;

        location / {
          proxy_set_header Host $http_host;
          proxy_pass http://my_app;
        }

    location /uploads/apks/ {
         alias /home/node/static/apks/;
         types {
          image/png png;
          image/jpeg jpg;
        }
    }   

}
  • When request get in, then Nginx point to /home/node/static/apks/, and because this volume was mounted to the real path in the OS ./apks, so should response the images there.

I am not sure what's the problem? or if any permission issues.

docker-compose.yml

version: '3'
services:
  nginx:
    image: nginx
    restart: always
    volumes:
        - ../apks:/home/node/static/apks
        - /xxx/certs:/etc/nginx/certs
        - /xxx/nginx/default.conf:/etc/nginx/conf.d/default.conf
    ports:
        - "80:80"
        - "443:443"
    links:
        - app
  app:
    container_name: my-app
    image: my-app
    restart: always
    build: .
    volumes:
        - ../apks:/home/node/static/apks

    ports:
       - "3000:3000"
    links:
        - mongo
  mongo:
    image: mongo:latest
    restart: always

    ports:
        - "27017:27017"

Dockfile

# https://docs.docker.com/samples/library/node/
ARG NODE_VERSION=12.10.0
# https://github.com/Yelp/dumb-init/releases
ARG DUMB_INIT_VERSION=1.2.2

# Build container
FROM node:${NODE_VERSION}-alpine AS build
ARG DUMB_INIT_VERSION

WORKDIR /home/node

RUN apk add --no-cache build-base python2 yarn && \
    wget -O dumb-init -q https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64 && \
    chmod +x dumb-init
ADD . /home/node
RUN yarn install && yarn build && yarn cache clean

# Runtime container
FROM node:${NODE_VERSION}-alpine

WORKDIR /home/node

COPY --from=build /home/node /home/node

EXPOSE 3000
CMD ["./dumb-init", "yarn", "start"]

here is the error log:

{"level":30,"time":1578817809651,"pid":35,"hostname":"5bb05c547cb6","req":{"id":3,"method":"GET","url":"/uploads/apks/5e1ac55962c6a800230d67fb-Screenshot%202019-12-21%20at%201.01.18%20AM.png","headers":{"host":"localhost:3000","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","upgrade-insecure-requests":"1","cookie":"keystone.sid=s%3Abg7rFgPthjLPes_UWkW2KLI5_HJUVTPN.5shrIzmAUa7zxiq5r5eMhr4N%2BcGlwicwA5Bbim4iV7s","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15","accept-language":"en-sg","accept-encoding":"gzip, deflate","connection":"keep-alive"},"remoteAddress":"::ffff:172.20.0.1","remotePort":43074},"res":{"statusCode":404,"headers":{"x-powered-by":"Express","x-keystone-app-version":"1.0.0","vary":"Origin, Accept-Encoding","access-control-allow-credentials":"true","content-security-policy":"default-src 'none'","x-content-type-options":"nosniff","content-type":"text/html; charset=utf-8","content-length":224}},"responseTime":2,"msg":"request completed","v":1}

Thanks for any help!

2
  • Apparently request was proxy passed and not processed by Nginx. You will need to improve nginx location configs. Commented Jan 12, 2020 at 11:11
  • @JanGaraj Could you a bit more specific? What does it mean by "not processed by Nginx"? I have no clue at all, thanks! Commented Jan 12, 2020 at 12:21

1 Answer 1

3

Finally solved by changing the permission of my static file folder sudo chmod -R 755 ~/apks.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.