Answer the question
In order to leave comments, you need to log in
How to redirect to domain names?
There is an external IP and several internal IPs. Sites weigh on internal IPs and there are 2 domain names site1.ru and site2.ru and each domain is configured to an external IP (1.1.1.1) How to configure nginx so that it can recognize domains and redirect to the appropriate IP?
For example:
I go to the site1.ru domain, I get to a site whose internal IP is 2.2.2.1
I go to the site2.ru domain, I get to a site whose internal IP is 2.2.2.2
At the moment, the situation is this. When you go to the site1.ru domain, the site opens, if you go to the external IP 1.1.1.1, then the Welcom nginx page opens and I know for sure that it is from site1.ru (2.2.2.1).
1.1.1.1 - external
2.2.2.1 - internal (Site1.ru)
2.2.2.2 - internal (site2.ru)
All sites are virtual
Answer the question
In order to leave comments, you need to log in
default_server option. More details https://nginx.ru/ru/docs/http/request_processing.html
Create 2 virtual hosts in Nginx:
First:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/Site1.ru/html;
index index.html index.htm;
server_name Site1.ru www.Site1.ru;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 80;
listen [::]:80;
root /var/www/site2.ru/html;
index index.html index.htm;
server_name site2.ru www.site2.ru;
location / {
try_files $uri $uri/ =404;
}
}
sudo ln -s /etc/nginx/sites-available/site1.ru/etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/site2.ru/etc/nginx/sites-enabled/
sudo service nginx restart
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question