Created
October 5, 2024 08:00
-
-
Save railroadman/24f16904c844d704433cbc8194daabfd to your computer and use it in GitHub Desktop.
docker-react-nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.8' | |
services: | |
react: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
ports: | |
- '5173:5173' | |
networks: | |
- my-network | |
restart: always | |
nginx: | |
image: nginx:alpine | |
ports: | |
- '80:80' | |
- '443:443' | |
volumes: | |
- ./nginx.conf:/etc/nginx/conf.d/default.conf | |
- ./cert.pem:/etc/nginx/cert.pem | |
- ./cert.key:/etc/nginx/cert.key | |
depends_on: | |
- react | |
networks: | |
- my-network | |
restart: always | |
networks: | |
my-network: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerfile | |
FROM node:18-alpine as build | |
WORKDIR /app | |
COPY package.json package-lock.json ./ | |
RUN npm install | |
COPY . . # Убедитесь, что копируется весь проект, включая index.html и все исходные файлы | |
RUN npm run build | |
EXPOSE 5173 | |
CMD ["npm", "run", "dev"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nginx.conf | |
server { | |
listen 80; | |
listen 443 ssl; | |
server_name _; | |
ssl_certificate /etc/nginx/cert.pem; | |
ssl_certificate_key /etc/nginx/cert.key; | |
location / { | |
proxy_pass http://react:5173; | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment