problem with / location stanza

Michael Barrett loki77 at gmail.com
Fri Apr 15 04:57:43 MSD 2011


Thanks Maxim & Francis - I think I'm just doing it the wrong way to begin with.  I've decided instead to try to use the uwsgi caching configs.

So I'm playing with that now, and I can't seem to get my app to cache a certain location.  Here's the basic config I'm using:

(In my http{}):

uwsgi_cache_path /data/nginx/cache levels=1:2 keys_zone=my-cache:10m;
uwsgi_temp_path /data/nginx/tmp;

(then in my server{}):

    location /event/1340113315 {
        uwsgi_pass ebdjango_uwsgi;
        uwsgi_cache my-cache;
        uwsgi_cache_valid any 10m;
        uwsgi_cache_key djcore$request_uri;
        access_log syslog test-cache;
        access_log /var/log/nginx/dj_access.log evb;
    }


When I run with this, and hit that URL, I'm seeing the test-cache log message showing up in my logfiles, so it's definitely hitting that location block.  That said, I don't see any files being created in /data/nginx/cache.  Also, when doing an strace of the nginx process, I see it passing the query back to the uwsgi process, so it doesn't look like the cache is being used at all.

Any hints on what I'm doing wrong here?  I get the feeling it's something dead simple, and I'm just glazing over it.

Thanks!


On Apr 13, 2011, at 5:15 PM, Francis Daly wrote:

> On Wed, Apr 13, 2011 at 03:06:04PM -0700, Michael Barrett wrote:
> 
> Hi there,
> 
>> I'm trying to make it so that if I get a request to / on my host to any hostname that doesn't start with 'www' it will check for a static page on the server, and if that doesn't exist it goes back to my uwsgi process for dynamic content. 
> 
> As you've seen, "if" inside "location" does probably not do what you
> want it to.
> 
> The usual nginx way is to have multiple server{} blocks with different
> server_name values.
> 
> http://nginx.org/en/docs/http/server_names.html has details.
> 
>> http://www.example.com/ - Goes to the uwsgi process
>> http://foo.example.com/ - Checks for a static file (/landing-cache/vanity:foo.html), if it can't find it it goes to the uwsgi process
>> http://foo.example.com/bar/ - Is dealt with in other location stanzas.
> 
> In your "not-www" server block, include the "location = /" block with
> the try_files. In your "www" server block, don't.
> 
> If you can enumerate your server names, that would be ideal. If not,
> perhaps you can use one "server_name www.*" and have the other be the
> default. And failing that, then perhaps something like
> 
>  server_name ~^(www\.)(?<domain>.+)$;
> 
> and
> 
>  server_name ~^(?<vanity>[^.]+)\.(?<domain>.+)$;
> 
> (which would give you $domain, as well as $vanity) could work.
> 
>>        try_files /landing-cache/vanity:$vanity.html @ebdjango_uwsgi;
> 
> 
> Or possibly, avoid all that and just set $vanity as the first bit of
> $host or $http_host, and make sure that /landing-cache/vanity:www.html
> does not exist.
> 
> It probably depends on what other differences you want between the
> various server_name configurations.
> 
> Good luck with it,
> 
> 	f
> -- 
> Francis Daly        francis at daoine.org
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx

--
Michael Barrett
loki77 at gmail.com







More information about the nginx mailing list