0

I have two nginx files located /etc/nginx/conf.d/

1st file `

docs.example.conf`

server {
    listen 80;
    server_name docs.example.su;


    return 302 https://docs.example.su$request_uri;
}

server {
    listen 443 ssl;
    ssl_certificate /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;
    server_name docs.example.su;

    access_log  /var/log/nginx/access_docs.log;
    error_log  /var/log/nginx/error_docs.log;
    root /home/build;

    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

2st file api.example.conf

server {
    listen 80;
    server_name api.example.su;
    return 302 https://api.example.su$request_uri;
}
server {
    listen 443 ssl;
    
    ssl_certificate /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;
    server_name api.example.su;
    client_max_body_size 100M;

    access_log  /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log;
    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;


 
    location / {
        proxy_pass http://127.0.0.1:8000; 
        proxy_set_header Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

api.example.conf - django project docs.example.conf - api documentation written in slate

Why when opening a page of any page with any subdomain from possible, including docs.example.su opens a django project, although it should open a project created on slate ?

As65
  • 3
  • 3
  • Use `nginx -T` (uppercase `T`) to view the entire configuration across all included files and ensure that both subdomains appear. The `server` block that appears first will be the default used for any other subdomain unless you [explicitly define a default server](http://nginx.org/en/docs/http/server_names.html#miscellaneous_names). – Richard Smith Aug 17 '23 at 08:25
  • I changed the location of the docs.example.su sites-available/default file and everything worked as it should. I just don't quite understand why – As65 Aug 17 '23 at 22:47

0 Answers0