H
H
Herman Martin2021-12-25 23:53:58
Nginx
Herman Martin, 2021-12-25 23:53:58

How to proxy a subdomain to a site folder?

what needs to be written in the nginx config so that when target.site.ru is opened,
everything works the same as when normal.site.ru/target is opened?

now the config looks like

server {
        listen 80;
        listen [::]:80;

        root /var/www/target.site.ru/html;
        index index.php index.html;

        server_name target.site.ru;

        location / {
            proxy_pass http://normal.site.ru/target;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
}


when opening target.site.ru in chrome, I get https://normal.site.ru/target/targettargettargetta...

in proxy_pass I tried with http and https, at the end with a slash / and without it. What is wrong? http://normal.site.ru/target;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Karabanov, 2021-12-26
@karabanov

Add "/" at the end:

server {
        ...

        location / {
            proxy_pass http://normal.site.ru/target/;
            ...
        }
}

proxy_pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question