A
A
account-42017-03-13 23:35:13
Nginx
account-4, 2017-03-13 23:35:13

How to set up nginx config for 2 nodejs applications (domain and subdomain)?

Launched 2 applications. One on port 3000, the other 5000.
nginx config:

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;
        }
}

What's wrong? Only the first application works. It also opens at old.example.com (the one on which I want to open the second one).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2017-03-14
@account-4

I have so:

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;
    #.......................
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question