R
R
Ruslan Egorov2015-10-26 11:59:03
Nginx
Ruslan Egorov, 2015-10-26 11:59:03

How to redirect a domain in nginx to another local IP address?

Available:
At the input of Mikrotik (external IP 99.99.99.99; local IP 192.168.0.1)
Web server NGINX (local IP 192.168.0.2)
Mail server iRedmail (local IP 192.168.0.3)
Settings:
On Mikrotik, external port 80 is forwarded to local IP 192.168.0.2:80 (NGINX)
On NGINX:

server {
       listen 80;
       server_name mail.babruisk.ru www.mail.babruisk.ru;

       location / {
              proxy_pass                  http://192.168.0.3:80/;
              proxy_set_header        Host mail.babruisk.ru;
              proxy_set_header        X-Real-IP          $remote_addr;
        }
}

Redirection does not work, but if you comment out two lines of proxy_set_header, then the domain is changed to a local address outside.
Please tell me how to set up redirection in nginx.
________________________________________________________________________________________________
The answer was found:
server {
       listen 80;
       server_name mail.babruisk.ru www.mail.babruisk.ru;

       location / {
              proxy_pass                  http://192.168.0.3:80;
              proxy_redirect            default;
              proxy_redirect            http://192.168.0.3:80/ http://mail.babruisk.ru/; 
        }
}

BUT The task has become more complicated:
Since iRedMail uses SSL and locally redirects everything from 80 to 443 via the NGINX config (.../mail .../SOGo .../iredadmin), I changed the config:
server {
    listen 80;
    listen 443;
    server_name mail.babruisk.ru www.mail.babruisk.ru;

    location / {
        proxy_pass      https://192.168.0.3:443;
        proxy_redirect  default;
        proxy_redirect  https://192.168.0.3:443/ https://mail.babruisk.ru/;
    }
}

Comes in from outside mail.babruisk.ru , shows its face, doesn’t go further (((
It gives an SSL error via https
I confess I don’t want to shovel the entire nginx config on the mail server, because there you can make mistakes and eventually dig in.
How to make the correct proxied https requests ?
_
_
server {
    listen 443;
    server_name mail.babruisk.ru www.mail.babruisk.ru;

    access_log  /var/log/nginx/ssl-access.log;

    ssl                 on;
    ssl_certificate     /var/ssl/iRedMail.crt;
    ssl_certificate_key /var/ssl/iRedMail.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;

    location / {
        proxy_pass      https://192.168.0.3/;
        proxy_redirect  off;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        Host $http_host;
        proxy_pass_header       Set-Cookie;
    }
}

I also transferred SSLki from the MAIL server to the WEB server.
Everything worked!!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Egorov, 2015-10-26
@regorov

Mihai, you smiled at me))) You won’t believe it, and there is no mail.babruisk.ru))) I won’t paint my network with real IP here)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question