1

Using Nginx with Django, I have the following location entry in my server config:

location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:1234;
}

Thus, all root URL requests are passed to Django.

Now, I'd like to serve some additional files, such as robots.txt, favicon.ico, and an indefinite number of other files, under the root URL as well. For example /robots.txt should return my robots.txt file, which lives in /var/www/project/misc/. How do I do this in Nginx? I can't seem to have several locations for capturing the root URL "/".

I know, I can do it like this:

location /robots.txt {
    alias /var/www/project/misc/robots.txt;
}

However, we're talking about a lot of different files, and adding an extra location for all of them seems to be rather clumsy. It would be better if there was a way for simply serving a whole directory under the root URL.

1 Answer 1

0

Just break out application into it's own @special location, then try the filesystem first.

location / {
    root /var/www/project/misc;
    try_files $uri @wsgiapp;
}

location @wsgiapp {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:1234;
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .