Answer the question
In order to leave comments, you need to log in
How to properly configure Nginx with Docker for static?
Hello.
There are three containers:
version: "3.5"
services:
nodejs:
container_name: nodejs
build:
context: .
dockerfile: docker/nodejs/Dockerfile
volumes:
- ./front:/app
ports:
- "3000:3000"
networks:
- test-network
php-fpm:
container_name: php-fpm
build:
context: .
dockerfile: docker/php-fpm/Dockerfile
volumes:
- ./back:/app
networks:
- test-network
nginx:
container_name: nginx
build:
context: .
dockerfile: docker/nginx/Dockerfile
volumes:
- ./back:/app
ports:
- "80:80"
depends_on:
- nodejs
- php-fpm
networks:
- test-network
networks:
test-network:
name: test-network
driver: bridge
events {}
http {
include /etc/nginx/mime.types;
server {
listen 80;
server_name test.work;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://nodejs:3000;
}
location /api/ {
rewrite ^/api/(.*)$ /$1 break;
include fastcgi_params;
fastcgi_param REQUEST_URI $document_uri;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param SCRIPT_FILENAME /app/web/index.php;
fastcgi_pass php-fpm:9000;
}
location /uploads {
root /app/web;
try_files $uri =404;
}
}
}
FROM node:lts-alpine
WORKDIR /app
COPY ./front/package*.json ./
RUN npm config set registry http://registry.npmjs.org/ && npm install && \
npm i webpack -g && \
npm i webpack-cli -g && \
npm i webpack-hot-middleware -g && \
npm i cross-env -g
COPY ./front ./app
EXPOSE 3000
CMD ["npm", "run", "server"]
Answer the question
In order to leave comments, you need to log in
1. Through the creation of location.
2. Similarly, through location.
3. Duplication does not occur, because volumes is not copied, but mounted. Of the possible problems there may be problems with file permissions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question