A
A
Alexey Yarkov2016-11-04 00:39:01
Nginx
Alexey Yarkov, 2016-11-04 00:39:01

How to fit 2 sites on one IP?

There are VPS. It costs Nginx and spins 2 nodejs applications. One listens on port 8080, the second on port 3000. And 2 configs for Nginx that connect to the main file.
First (website is up):

server {
    listen 80;
    server_name domen.ru www.domen.ru;
    proxy_set_header Host domen.ru;

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

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

server {
    listen       443 ssl http2;
    server_name  domen.ru www.domen.ru;
    # и дальше настройки SSL и т. п.
    # все работает
    .........
}

Second (website NOT working):
server {
        listen 80;
        server_name domen2.ru www.domen2.ru;

        access_log  /home/vpsuser/projects/log/domen2.ru/access.log combined;
        error_log  /home/vpsuser/projects/log/domen2.ru/error.log  warn;

        location / {
                proxy_pass http://localhost:3000;
        }
}

The second site does not use SSL. And here's what's strange: I enter the address of the second site in the browser - the first one opens, and if $ curl domen2 in the console , then everything is OK.
CHADNT?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gregory House, 2016-11-04
@theemfs

Who did you write the documentation for?
nginx.org/ru/docs/http/configuring_https_servers.html

M
Mikhail Osher, 2016-11-04
@miraage

You may have deleted the default nginx config.
Do something like this very first in sites-available.

server {
  listen 80;
  server_name _;
  location / {
    return 204;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question