I
I
IvanSerr2019-11-29 19:29:21
System administration
IvanSerr, 2019-11-29 19:29:21

How to link multiple sites to one IP?

There is 1 "white" IP and 3 virtual servers. The main site site.ru ("Lampa" on CentOS 7) is located on 1 virtual machine. How to make it so that when accessing the name1.site.ru subdomain, the site from 1 virtual server becomes friends, and when accessing name2.site.ru - to another?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2019-11-29
@IvanSerr

All requests should be caught by a single server, for example, nginx.
By request headers, Host: ...redirect / proxy the request to acc. virtual server.

server {
  server_name site.ru;
  location / {
        proxy_pass http://127.0.0.1:8000; # допустим, тут слушает основной
        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;
        # ... ещё инструкции - передача заголовков, кэширование..
    }
}

server {
  server_name name1.site.ru;
  location / {
      proxy_pass http://127.0.0.1:8001; # вирт-1
      # ...
  }
}

server {
  server_name name2.site.ru;
  location / {
      proxy_pass http://127.0.0.1:8002; # вирт-2
      # ...
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question