У меня на хосте работает nginx. Он перенаправляет в контейнер docker на порт 5000 при доступе к / admin и при записи / перенаправляет на порт 80.
Хотя перенаправление работает, файлы js и css не загружаются контейнером реакции. Я вижу, что заголовок страницы меняется на заголовок контейнера React, но на вкладке сети в Google отображается 404 для всех файлов js.
Что мне не хватает?
THE DOCKER ФАЙЛ
FROM node as builder
COPY package.json package-lock.json ./
RUN npm install && mkdir /react-ui && mv ./node_modules ./react-ui
WORKDIR /react-ui
COPY . .
RUN npm run build
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
RUN rm -rf /usr/share/nginx/html/*
# COPY ./build /var/www
COPY --from=builder /react-ui/build /usr/share/nginx/html
EXPOSE 5000
ENTRYPOINT ["nginx","-g","daemon off;"]
NGINX КОНФИГ ВНУТРИ DOCKER
# auto detects a good number of processes to run
worker_processes auto;
#Provides the configuration file context in which the directives that affect connection processing are specified.
events {
# Sets the maximum number of simultaneous connections that can be opened by a worker process.
worker_connections 8000;
# Tells the worker to accept multiple connections at a time
multi_accept on;
}
http {
# what times to include
include /etc/nginx/mime.types;
# what is the default one
default_type application/octet-stream;
# Sets the path, format, and configuration for a buffered log write
log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $upstream_addr '
'"$http_referer" "$http_user_agent"';
server {
# listen on port 80
listen 5000;
# save logs here
access_log /var/log/nginx/access.log compression;
# where the root here
root /usr/share/nginx/html;
# what file to server as index
index index.html index.htm;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to redirecting to index.html
try_files $uri $uri/ /index.html;
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# Javascript and CSS files
location ~* \.(?:css|js)$ {
try_files $uri $uri/ /index.html;
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# Any route containing a file extension (e.g. /devicesfile.js)
location ~ ^.+\..+$ {
try_files $uri =404;
}
}
}
NGINX НА ХОСТЕ
location /admin/ {
proxy_pass http://127.0.0.1:5000/;
}