Home>

I stumbled a little with the Nginx settings and asked a question.
Currently, if there is only one of the following configuration files (test.conf), the address can be accessed without problems, but when the test.conf file is divided, if you access the address that describes the settings, This is a situation where a 404 error occurs.

server {
    listen 443;
    ssl on;
    server_name dev.test.site;
    ssl_certificate /etc/letsencrypt/live/dev.test.site/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/dev.test.site/privkey.pem;
    root/var/www/django;
    charset utf-8;

    location/test-tool {
        alias/var/www/django/tool/client/dist;
        try_files $uri $uri//var/www/django/tool/client/dist/index.html;
        #alias/var/www/django/tool/client/dist;
    }
    location/api/display {
        include/etc/nginx/uwsgi_params;
        uwsgi_pass unix: /run/uwsgi/tool_uwsgi.sock;
    }
    location/api/search/{
        include/etc/nginx/uwsgi_params;
        uwsgi_pass unix: /run/uwsgi/tool_uwsgi.sock;
    }
    location/ap/static {
        alias/var/www/django/tool/ap/static;# your Django project's static files --amend as required
        #alias/var/www/django/tool/ap/static
        # root/var/www/django/tool/ap/static
    }
    location/ap {
        include/etc/nginx/uwsgi_params;
        uwsgi_pass unix: /run/uwsgi/tool_uwsgi.sock;
    }
    location/test-2 {
        include/etc/nginx/uwsgi_params;
        uwsgi_pass unix: /run/uwsgi/test-2_uwsgi.sock;
    }
}


Here, it is currently divided into the following two files.
The following istool.confIt is a file.

server {
    listen 443;
    ssl on;
    server_name dev.test.site;
    ssl_certificate /etc/letsencrypt/live/dev.test.site/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/dev.test.site/privkey.pem;
    root/var/www/django;
    charset utf-8;

    location/test-tool {
        alias/var/www/django/tool/client/dist;
        try_files $uri $uri//var/www/django/tool/client/dist/index.html;
        #alias/var/www/django/tool/client/dist;
    }
    location/api/display {
        include/etc/nginx/uwsgi_params;
        uwsgi_pass unix: /run/uwsgi/tool_uwsgi.sock;
    }
    location/api/search/{
        include/etc/nginx/uwsgi_params;
        uwsgi_pass unix: /run/uwsgi/tool_uwsgi.sock;
    }
    location/ap/static {
        alias/var/www/django/tool/ap/static;# your Django project's static files --amend as required
        #alias/var/www/django/tool/ap/static
        # root/var/www/django/tool/ap/static
    }
    location/ap {
        include/etc/nginx/uwsgi_params;
        uwsgi_pass unix: /run/uwsgi/tool_uwsgi.sock;
    }


And the followingtest2.confIt is a file.

server {
    listen 443;
    root/var/www/django;
    location/test-2 {
        include/etc/nginx/uwsgi_params;
        uwsgi_pass unix: /run/uwsgi/tool_uwsgi.sock;
    }
    charset utf-8;

I don't understand why when the file is split, the display changes when it is accessed.
We would appreciate it if you could give us some advice regarding this phenomenon.

※P.S.
After splitting the configuration file and before splitting, the accessed address will be "https://dev.test.site/ap/admin".

  • Answer # 1

    server_name dev.test.site;It was a problem that occurred because the server_name is the same in the two files in this part.
    This time, since the domain is the same, we decided to use one configuration file to support it.