account-4
@account-4

Как настроить конфиг nginx на 2 nodejs приложения (домен и субдомен)?

Запущено 2 приложения. Одно на порту 3000, другое 5000.

Конфиг nginx:

server {

        listen 80;
        listen [::]:80;
        server_name example.com;
        return 301 https://$server_name$request_uri;

}
server {

        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        include snippets/ssl-example.com.conf;
        include snippets/ssl-params.conf;

        location / {
                proxy_pass http://localhost:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
        }

        location /.well-known {
                root /home/ubuntu/again/222/static;
        }
}

server {

        listen 80;
        listen [::]:80;
        server_name old.example.com;
        return 301 https://$server_name$request_uri;

}
server {

        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        include snippets/ssl-example.com.conf;
        include snippets/ssl-params.conf;

        location / {
                proxy_pass http://localhost:5000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
        }
}


Что не так? Работает только первое приложение. Оно же открывается и по адресу old.example.com (то, на котором хочу открывать второе).
  • Вопрос задан
  • 844 просмотра
Решения вопроса 2
yarkov
@yarkov
Помог ответ? Отметь решением.
У меня так:
server {
    listen 80;
    server_name api.domain.ru www.api.domain.ru;
    proxy_set_header Host api.domain.ru;

    location / {
        rewrite ^(.*)$ https://api.domain.ru$1 permanent;
    }

    return 301 https://api.domain.ru$request_uri;
}

server {
    listen       443 ssl http2;
    server_name  api.domain.ru www.api.domain.ru;
    #......................
}
#################################################################
server {
    listen 80;
    server_name domain.ru www.domain.ru;
    proxy_set_header Host domain.ru;

    location / {
        rewrite ^(.*)$ https://domain.ru$1 permanent;
    }

    return 301 https://domain.ru$request_uri;
}

server {
    listen       443 ssl http2;
    server_name  domain.ru www.domain.ru;
    #.......................
}
Ответ написан
@tagplus5
В разделе, где находится listen 443 нет server_name, поэтому срабатывает default_server.
Надо добавить server_name old.example.com; в последний конфиг.
listen 443 ssl http2;
server_name old.example.com;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы