nginx переписывают определенный субдомен к nonssl

У меня есть 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;
}
0
задан 19 August 2015 в 01:48
1 ответ

Вы должны определить несколько блоков серверов . См. эту страницу , чтобы узнать о приоритете имя_сервера .

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;
}
0
ответ дан 5 December 2019 в 12:16

Теги

Похожие вопросы