У меня есть 301 перенаправление, которое пишет все субдомены в https. теперь, клиент хотел бы иметь http только субдомен. как я должен поймать этот запрос в https сервере и перенаправить его к http?
server {
listen 80;
charset utf-8;
server_name *.example.com;
# need to catch specific subdomain here and redirect it to http permanent.
# i know this is wrong, but it illustrates what i must do
if($host == 'subdomain.example.com'){
return 301 http://subdomain.example.com$request_uri?$query_string;
}
# else continue redirect as normal
return 301 https://example.com$request_uri?$query_string;
}
Вы должны определить несколько блоков серверов
. См. эту страницу , чтобы узнать о приоритете имя_сервера
.
server {
listen 80;
server_name subdomain.example.com;
# ... what you want to serve at http://subdomain.example.com/ ...
}
server {
listen 80;
server_name example.com *.example.com;
return 301 https://example.com$request_uri?$query_string;
}
server {
listen 443 ssl;
server_name example.com;
# ... what you want to serve at https://example.com/ ...
}
server {
listen 443 ssl;
server_name subdomain.example.com;
return 301 http://subdomain.example.com$request_uri?$query_string;
}