Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using nginx/uWSGI/Django, and getting some unexpected 301 redirects, one from the root/, and one from /robots.txt.

I think the robots.txt might be due to how I have the alias configured - if so, is there any way to change it to directly serve the file without a redirect?

And I don't see any reason why / should be redirected? I'm only redirecting domains that start with www, so shouldn't nginx just pass / straight through to django?

Update: Okay, here's the entire config file. The only differences are that I use an include sites/*, which I condensed into one file here, and deleted a few expires max directives (and changed a few names, like mysite):

# access log file
301 216.145.17.190 [GET /robots.txt HTTP/1.0] (178 bytes)

301 216.145.17.190 [GET / HTTP/1.1] (178 bytes) [http://whois.domaintools.com/me.com]
200 216.145.17.190 [GET / HTTP/1.1] (34 bytes) [http://whois.domaintools.com/me.com]

# nginx.conf
user nginx;
worker_processes 2;
worker_rlimit_nofile 2048;
daemon off;
error_log /home/me/logs/nginx_error.log warn;
events { worker_connections  1024; }
http {
    log_format mine '[$time_local]: $status $remote_addr [$request] ($body_bytes_sent bytes) : $remote_user [$http_referer]';
    include       mime.types;
    default_type  application/octet-stream;
    access_log /home/me/logs/nginx_access.log mine;
    ignore_invalid_headers  on;
    server_tokens   off;
    sendfile        on;
    keepalive_timeout  65;

    server {  # ignore invalid hosts.
        listen       80;
        server_name  "";

        location /whm-server-status {
            access_log /home/me/logs/whm.log; # was off
            error_log /dev/null info;
            return 444;
        }
        return 444;
    }

    server { # redirect www.domain to domain permanently.
        listen       80;
        server_name  www.mysite.com;
        rewrite ^ http://mysite.com$uri? permanent;
    }

    server {
        listen       80;
        server_name  mysite.com;
        root  /home/me/www/nginx;
        autoindex off;
        log_subrequest  on;
        rewrite_log on;

        location / {    # django pass-thru via uWSGI
            uwsgi_pass 127.0.0.1:8088;
            include uwsgi_params;
        }
        location /static/ { alias /home/me/www/static/; }
        location /static/admin/ {alias (long django path deleted) }
        location /robots.txt { alias /home/me/www/static/robots.txt; }
        location /favicon.ico { alias /home/me/www/static/favicon.ico; }
    }
}

Minor note - while I'm building the site, the robots.txt is deny all, don't know if that would affect the request for root.

Another problem is that the attempt to turn off logging whm-server-status, doesn't work, no idea why either. :)

share|improve this question
    
You have edited your config too much for it to be useful. Nothing there is causing redirects outside of www.me.com to me.com. –  Martin Fjordvald Jul 20 '11 at 2:16
    
@Martin F, there isn't much more to my config - I have a server "" directive that returns 444, and locations favicon.ico and /static/admin (for django admin), plus a few directives like autoindex off. I could be missing something important, but nothing else looked relevant, anyway. :) –  Cyclops Jul 20 '11 at 12:14
    
Alias doesn't redirect, so whatever it is that's wrong is not included in your paste. –  Martin Fjordvald Jul 20 '11 at 17:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.