I
I
Ilya2014-10-15 01:12:01
Nginx
Ilya, 2014-10-15 01:12:01

NGINX: How to give one thing by domain and another by ip?

There is a site on the server, it is shown when entering the domain. When entering the server simply by IP, a standard page from nginx is given. I would like to hang up 2 site and that it was given by ip (instead of the standard one from nginx). I don't understand how to implement it.

upstream my_project {
    server unix:/tmp/myproject.sock fail_timeout=0;
}

server {
    listen 80;
    server_name  100.100.100.100;
}

server {
    listen 80;
    client_max_body_size 4G;
    server_name 100.100.100.100;
    access_log  /home/myuser/logs/myproject/myproject.nginx..log;
    keepalive_timeout 5;

    root /home/myuser/projects/myproject/;
    
    location / {
        proxy_pass http://100.100.100.100;
    }

}

This is the config for uploading by ip, but it does not work.
I would be glad to send to the manual with a solution to the problem, and not just "smoke the manuals."

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Misbakh-Soloviev, 2014-10-15
@FireGM

server_name may well be an IP, only, in your config, server_name is duplicated in two different server {} blocks. That's probably why it doesn't work.
Alternative - You can specify use server_name _;( or any other non-existent value ).
And to avoid rebound

standard page from NginX
- in one of the blocks (preferably the first one in the config / among the includes, because otherwise there will be problems with SSL later) specify the default_server directive for listen

S
Sergey, 2014-10-15
Protko @Fesor

well, do not prescribe server_name and you will be happy. Actually read what it is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question