Я использую docker-compose
для развертывания приложения Nodejs (Keystone JS). Я хочу получить доступ к stati c png по URL-адресу, например: http://localhost: 3000 / uploads / apks / 5e1ac55962c6a800230d67fb-test.png Прямо сейчас у меня ошибка 404.
Есть 3 контейнера, Nginx, app, mongo
.
Структура папок
- apks
- myapp
- Dockfile
- docker -compose.yml
Вот моя структура:
- Изображения находятся в
apks
- Установите setti c псевдоним в Nginx файле конфигурации в docker папка контейнера приложения:
/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;
}
}
}
- Когда запрос поступит, тогда Nginx указывают на
/home/node/static/apks/
, и поскольку этот том был подключен к реальному путь в ОС ./apks
, поэтому должны откликаться изображения там.
Я не уверен, в чем проблема? или в случае каких-либо разрешений.
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"]
Вот журнал ошибок:
{"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}
Спасибо за любую помощь!