Score:0

Cannot reach domain defined by server_name

gs flag

I'm trying to map my backend server at http://api:4000 to my-domain.site, where api is the name of my backend service in docker compose.

I run docker compose up and everything works fine, but I can only access my backend server at localhost, not my desired domain being my-domain.site.

enter image description here

Below are my docker-compose.yml file and nginx configuration file:

docker-compose.yml

nginx:
    image: nginx:alpine
    container_name: nginx
    restart: always
    ports:
      - "80:80"
      - "443:443"
    command: nginx -g "daemon off;"
    volumes:
      - ./conf.d:/etc/nginx/conf.d
      - ./hosts:/etc/hosts
    depends_on:
      - api

api:
    container_name: backend
    build:
      context: ./backend
      dockerfile: Dockerfile
    command: npm start
    ports:
      - "4000:4000"

conf.d/default.conf

server {
  listen 80;
  server_name my-domain.site;
  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_pass http://api:4000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}
Jaromanda X avatar
ru flag
and how have you tried to get `my-domain.site` to resolve to the appropriate IP address?
William Le avatar
gs flag
@JaromandaX yes I tried putitng into `/etc/hosts` this line `127.0.0.1 my-domain.site` but that does not work either
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.