• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Microcaching - Nginx - Plesk 11.5

Imad S

New Pleskian
Hey,

I need help enabling microcaching on a server with plesk running nginx. I have a sample config but for the life of me can't figure out where to put it:

the script
Code:
# Set cache dir
proxy_cache_path /var/cache/nginx levels=1:2 
                 keys_zone=microcache:5m max_size=1000m;

# Virtualhost/server configuration
server {
    listen   80;
    server_name  yourhost.domain.com;

    # Define cached location (may not be whole site)
    location / {

        # Setup var defaults
        set $no_cache "";

        # If non GET/HEAD, don't cache & mark user as uncacheable for 1 second via cookie
        if ($request_method !~ ^(GET|HEAD)$) {
            set $no_cache "1";
        }

        # Drop no cache cookie if need be
        # (for some reason, add_header fails if included in prior if-block)
        if ($no_cache = "1") {
            add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";            
            add_header X-Microcachable "0";
        }

        # Bypass cache if no-cache cookie is set
        if ($http_cookie ~* "_mcnc") {
            set $no_cache "1";
        }

        # Bypass cache if flag is set
        proxy_no_cache $no_cache;
        proxy_cache_bypass $no_cache;

        # Point nginx to the real app/web server
        proxy_pass http://appserver.domain.com;

        # Set cache zone
        proxy_cache microcache;

        # Set cache key to include identifying components
        proxy_cache_key $scheme$host$request_method$request_uri;

        # Only cache valid HTTP 200 responses for 1 second
        proxy_cache_valid 200 1s;

        # Serve from cache if currently refreshing
        proxy_cache_use_stale updating;

        # Send appropriate headers through
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # Set files larger than 1M to stream rather than cache
        proxy_max_temp_file_size 1M;

        # Custom logging
        log_format custom '$remote_addr - $remote_user [$time_local]  '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent" nocache:$no_cache';
        access_log  /var/log/nginx/microcache.log custom;

    }

}

I've tried adding it, the code inside the Location tag, to the Additional Nginx directives section of the domain but it throws an error saying the add_header tag can't go there.

I've looked at the nginx.conf at /var/www/vhosts/system/<domain>/conf but it says that the file was automatically generated and that any changes would be removed.
 
Last edited:
Back
Top