Answer the question
In order to leave comments, you need to log in
How to configure docker and nginx so that the API works on next.js?
Good afternoon! I decided to try docker for my project. Project on next.js I
use docker-compose. Everything is fine until I add a container with nginx to the project.
The browser gives an error -
Access to XMLHttpRequest at ' localhost:3000/api/categories ' from origin ' surgut.expert.local ' has been blocked by CORS
Error: connect ECONNREFUSED 127.0.0.1:80
version: '3'
services:
next:
build: ./next
container_name: surgut-expert-next
command: npm run dev
volumes:
- ./next:/usr/src/app
restart: unless-stopped
ports:
- "3000:3000"
networks:
- surgut-expert-network
nginx:
image: nginx:stable-alpine
container_name: surgut-expert-nginx
ports:
- "80:80"
volumes:
- ./nginx/nginx.conf.dev:/etc/nginx/conf.d/nginx.conf
depends_on:
- next
- phpmyadmin
- db
networks:
- surgut-expert-network
db:
image: mysql
container_name: surgut-expert-db
volumes:
- dbdata:/var/lib/mysql
restart: always
ports:
- "3036:3036"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: surgut_expert
networks:
- surgut-expert-network
phpmyadmin:
image: phpmyadmin
container_name: surgut-expert-phpmyadmin
restart: always
ports:
- "1234:80"
environment:
- PMA_ARBITRARY=1
networks:
- surgut-expert-network
volumes:
dbdata:
networks:
surgut-expert-network:
driver: bridge
server {
listen 80;
server_name surgut.expert.local;
location / {
proxy_pass http://next:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host; proxy_cache_bypass $http_upgrade;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question