Boris Burkov
Boris Burkov

Reputation: 14436

Nginx responds to a server_name, while it shouldn't

I'm developing a new site, for which I have production and development versions. Production version is currently turned off and only development version is used for testing purposes. Both versions are located on the same IP address and have domain names example.com and develop.example.com.

I have 2 corresponding configuration files in my nginx /etc/apps/sites-available: example.conf and develop.example.conf, only develop.example.conf is enabled by a symlink in sites-enabled. SSL is enabled and all http connections are redirected to https.

Still, for some reason https://example.com shows the development version of my site. Why?

Here is develop.example.conf:

upstream django_develop {
    server unix:///tmp/develop.sock;
}

rewrite_log on;

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

server {
    listen 443 ssl;

    server_name develop.example.com;
    ssl_certificate /etc/ssl/private/example.crt;
    ssl_certificate_key /etc/ssl/private/example.key;
    charset utf-8;

    client_max_body_size 75M;

    location /media {
        alias /srv/develop/mysite/media;
    }

    location /static {
        alias /srv/develop/static;
    }

    location / {
        uwsgi_pass django_develop;
        include /etc/nginx/uwsgi_params;
    }
}

Strangely, error.log doesn't contain any rewrite entries.

Upvotes: 0

Views: 53

Answers (1)

Donovan Hernandez
Donovan Hernandez

Reputation: 476

If you don't have a catch-all server block, it'll default to the first one. You can read more about it here: http://nginx.org/en/docs/http/request_processing.html

Upvotes: 2

Related Questions