B
B
bengur22022-04-04 11:38:41
Nginx
bengur2, 2022-04-04 11:38:41

How to handle all domains through Nginx inside a container?

A container is running on the virtual machine.

Dockerfile

FROM nginx:latest

COPY my.conf /etc/nginx/conf.d/

EXPOSE 80
EXPOSE 443


my.conf
server {
    listen 80;
    server_name localhost;

    location / {
        access_log off;
        default_type text/plain;
        add_header Content-Type text/plain;
        return 200 "localhost alive";
    }
}

server {
    listen 80;
    server_name test.com;

    location / {
        access_log off;
        default_type text/plain;
        add_header Content-Type text/plain;
        return 200 "test.com alive";
    }
}

server {
    listen 80;
    server_name site.com;

    location / {
        access_log off;
        default_type text/plain;
        add_header Content-Type text/plain;
        return 200 "site.com alive";
    }
}


On the virtual machine, the container responds
curl http://localhost
Returns localhost alive

Trying to set up domains.
site.com and test.com are directed to the IP of the server using A-records.
Returns an error:

ERR_CONNECTION_REFUSED


UPD 1
Here is a discussion of open ports:
https://qna.habr.com/q/1136198

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
akelsey, 2022-04-04
@bengur2

call by name curl http://test.comget test.com alive
call by name curl http://site.comget site.com alive
of course provided that test.com & site.com point to the host where the Docker engine is running.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question