Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


nginx question
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

nginx question

jcalebjcaleb Member
edited November 2012 in General

hello, i need nginx help

i am experimenting nginx caching, and this works:

fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:5m max_size=1000m;

server {
    listen 80;
    server_name domain.com www.domain.com;
    access_log /var/log/nginx/website.access_log;
    error_log /var/log/nginx/website.error_log;
    root /home/jon/temp/php/domain.com;
    index index.php index.htm index.html;
    location ~ .php$ {
        try_files $uri $uri/ /index.php;
        set $no_cache "";
        if ($request_method !~ ^(GET|HEAD)$) {
            set $no_cache "1";
        }
        if ($no_cache = "1") {
            add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
            add_header X-Microcachable "0";
        }
        if ($http_cookie ~* "_mcnc") {
                    set $no_cache "1";
        }
        fastcgi_no_cache $no_cache;
        fastcgi_cache_bypass $no_cache;
        fastcgi_cache microcache;
        fastcgi_cache_key $server_name|$request_uri;
        fastcgi_cache_valid 404 30m;
        fastcgi_cache_valid 200 10s;
        fastcgi_max_temp_file_size 1M;
        fastcgi_cache_use_stale updating;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass_header Set-Cookie;
        fastcgi_pass_header Cookie;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param  PATH_INFO          $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
        include fastcgi_params;

my question is, can i use the microcache for multiple domains? e.g. define fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:5m max_size=1000m; in nginx.conf and use microcache for all domain in server? or is cache one for each domain i will host?

sorry, i am not very well versed with nginx. thanks!

Comments

  • Hi
    you can get some help in http://wiki.nginx.org/HttpProxyModule
    it says:
    proxy_cache zone
    ...
    This directive sets name of zone for caching. The same zone can be used in multiple places.
    ...

  • thank you

  • XSXXSX Member, Host Rep

    the cache just is proxy_cache.

  • kbeeziekbeezie Member
    edited November 2012

    By the way if/set/rewrite will occur before try_files does. As such if you insist on using if blocks, switch back to the older rewrite method instead of try_files in order for them to trigger in the order you expect.

  • @kbeezie said: By the way if/set/rewrite will occur before try_files does. As such if you insist on using if blocks, switch back to the older rewrite method instead of try_files in order for them to trigger in the order you expect.

    How to do that? Or should I remove the try_files? Thanks

  • No offense and not trying to tell you to gtfo but sign up on the nginx mailing list and if you have any nginx questions, those folks answer back real quick. Even with bug fixes.. those crazy Russians and their webservers

  • thanks man!

  • @jcaleb or use the rewrite method instead of try_files, the nginx wiki has basic coverage on all of those pitfalls/etc.

  • Thank you @kbeezie

Sign In or Register to comment.