U
U
User992018-05-25 11:07:02
Nginx
User99, 2018-05-25 11:07:02

How to proxy requests in nginx?

There is a server with a website (mysite.ru) on IIS (server ip 192.168.1.2) + several Asp.net web applications (web1.mysite.ru, web2.mysite.ru ...).
It was required to add a site on ngnix or on apache (the engine on iis does not work, after shamanism it started working, but crookedly). I installed ngnix on the ubuntu virtual machine (server ip 192.168.1.3).

upstream web_servers {
server 192.168.1.2;
server 192.168.1.3;
}
#порт
server {
listen 80;
location / {
proxy_pass http://mysite.ru;
# настройка заголовков
proxy_set_header X-proxy 192.168.1.3;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_next_upstream     error timeout invalid_header http_500 http_404;
proxy_set_header X-Client-IP $remote_addr;
}
}

Question: How to redirect requests to the correct server? for example, the user enters in the browser: mysite.ru nginx should process it and send it to the IIS server, that is, to 192.168.1.2, if it accesses the web1.mysite.ru web application, it should also send to IIS, and if corp1.mysite.ru then the site should load on nginx. Am I on the right track? what should be done and how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Rakhinsky, 2018-05-25
@rakhinskiy

server {
    listen 80;
    server_name mysite.ru;
    location / {
        proxy_pass http://192.168.1.2;
        proxy_set_header X-proxy 192.168.1.3;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Client-IP $remote_addr;
    }
}
server {
    listen 80;
    server_name web1.mysite.ru;
    location / {
        proxy_pass http://192.168.1.2;
        proxy_set_header X-proxy 192.168.1.3;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Client-IP $remote_addr;
    }
}
server {
    listen 80;
    server_name corp1.mysite.ru;
    root /var/www/corp1.mysite.ru
    Тут описываете свои location для сайта (php/статика/....)
}

You don't need upstream since the servers are not duplicated
Well, you definitely don't need to add nginx as an upstream

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question