M
M
miwang2015-09-27 23:59:08
Nginx
miwang, 2015-09-27 23:59:08

Nginx, rewrite or proxy_pass. How to translate from site.ru/page/ to page.site.ru?

Good day!
nginx + php-fpm config.
Website site.ru
How to transfer the internal page page to a subdomain? For example:
site.ru/page/ -> page.site.ru ?
It is necessary that the page opens on both URLs, but in the address bar, so that it is page.site.ru

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Antony Ryabov, 2015-09-28
@tonymadbrain

You make two servers (two virtual hosts). First:

server {
    server_name  site.ru;
    location =/page/ {
      rewrite ^(.*) http://page.site.ru$1 permanent;
    }
}

and the second one with a subdomain:
server {
    server_name page.site.ru;
   ...
}

This is a simple but not the best solution.

M
mivang, 2015-09-28
@mivang

I checked the configs above, it turns out like this:
the 1st host, when trying to go to site.ru/page, redirects to page.site.ru/page/, but there is no such page, so error 404
2nd host what rules to set?
If you change the 1st config, remove $1, and specify proxy_pass site.ru in the second config, then when you go to site.ru/page, it will redirect to page.site.ru - which was required, however, the content will be the same as on the main page (site.ru), not page.
1st host

server {
  server_name site.ru

  location =/page/ {
            rewrite ^(.*) http://page.site.ru permanent;
        }
}

2nd host
server {
  server_name page.site.ru

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

If you put proxy_pass site.ru/page in the 2nd config, then as a result there will be errors with cyclic redirection.
How to be?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question