I
I
i_want_to_know_everything2017-09-25 15:38:24
Nginx
i_want_to_know_everything, 2017-09-25 15:38:24

Nginx sites on the same ip?

there is a server, on it several sites all on different ip
configs of each site begin so

listen ***.***.***.***:80;
server_name domain.com;
root /var/www/domain.com/html;
index index.php;

Everything works fine
on 1 ip, it was necessary to hang up a few more sites
with the same config for each domain on this ip, the same site opens.

What is the reason? How to decide?
Upd: Full config

It differs for different sites only by domain

server {
    listen xxx.xxx.xxx.xxx:80;
    return 301 https://domain.com$request_uri;
    server_name domain.com;
}


server {
  listen xxx.xxx.xxx.xxx:443 ssl;
  server_name domain.com;
  root /var/www/domain.com/html;
    index index.php;
  
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        add_header Strict-Transport-Security max-age=31536000;
        ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
        ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
        ssl_dhparam /etc/nginx/ssl/dhparam.pem;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;

   location ~* \.(?:manifest|appcache|html?|xml|json)$ {
        expires -1;
        # access_log logs/static.log; # I don't usually include a static log
   }

    location ~* \.(?:rss|atom)$ {
        expires 1h;
        add_header Cache-Control "public";
    }

        location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff)$ {
        expires 1M;
        access_log off;
        add_header Cache-Control "public";
    }

    location ~* \.(?:css|js)$ {
        expires 1y;
        access_log off;
        add_header Cache-Control "public";
    }

    location / {
      try_files $uri $uri/ /index.php?$args;
    }

    
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /var/www/domain.com/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Mukovoz, 2017-09-25
@i_want_to_know_everything

If everything is exactly as you said, then everything should work. But I understand you missed a lot. Throw off configs I will prompt where you stumble.

M
Mikhail Grigoriev, 2017-10-03
@Sleuthhound

1. To understand how Nginx handles requests, be sure to read this
2. Also, be sure to define default_server, for example, in the /etc/nginx/conf.d/fallback.conf file (the path may change, see include in nginx.conf) you can write :

server {
        listen XX.XX.XX.XX:80 default_server;
        server_name _;
        return 444;
}

default_server is useful for processing incorrect requests, for example, requests without the "Host" field.
In my example, just above, nginx will simply close the connection for such requests, for this a special is used. code 444.

F
Fixid, 2017-09-25
@Fixid

Need full config

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question