Answer the question
In order to leave comments, you need to log in
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
You make two servers (two virtual hosts). First:
server {
server_name site.ru;
location =/page/ {
rewrite ^(.*) http://page.site.ru$1 permanent;
}
}
server {
server_name page.site.ru;
...
}
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;
}
}
server {
server_name page.site.ru
location / {
proxy_pass http://site.ru/;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question