X
X
xxx2018-02-09 19:29:29
Nginx
xxx, 2018-02-09 19:29:29

Set up 2 server blocks on different ports, but both of them go to one block?

First block

server {
        listen 8003 default_server;
        listen [::]:8003 default_server;
        root /var/www/site1;
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
        server_name my_ip;
        location / {
                try_files $uri $uri/ =404;
        }
           error_page 404 /404.html;
        location = /404.html {
                root /var/www/site1;
                internal;
        }
}

Second block
server {
        listen 8002 default_server;
        listen [::]:8002 default_server;
        root /var/www/site2;
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
        server_name my_ip;
        location / {
                try_files $uri $uri/ =404;
        }
           error_page 404 /404.html;
        location = /404.html {
                root /var/www/site2;
                internal;
        }
}

Made links in sites-enabled.
I did systemctl restart nginx
I knock on 8002, 8003 I get to site1.
What's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2018-02-12
@Heavy10110

default_server
is used 1 time on the server and serves as /dev/nullfor unparsed requests, and not everything in a row as you think.
It is needed in order to show you a picture of hello, you are on the server but something went wrong.
Especially when not a single site is yet tied to the server, but you need to show its performance.
In order not to embarrass the server, prescribe normal site names.

server {
        listen 8002;
        server_name site2.ru www.site2.ru ;
        root /var/www/site2.ru
...

W
Wexter, 2018-02-09
@Wexter

1) You have the same content of site1 and site2.
2) You have servers registered somewhere else on these ports with a different server_name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question