WordPress.org

Ready to get started?Download WordPress

Forums

Lack of Nginx support from WP Super Cache (6 posts)

  1. hollywoodgrind
    Member
    Posted 4 years ago #

    Very heavily trafficked WordPress blogs are moving away from Apache to Nginx. In fact, WordPress itself uses Nginx in their server mix.

    I've been waiting for the day when WP Super Cache would have a set of regular expressions for Nginx that match the /.htaccess and wp-content/cache/.htaccess Apache files. Currently the Nginx community uses the barebones regular expressions below for Super Cache:

    # if the requested file exists, return it immediately
                            if (-f $request_filename) {
                            break;
                            }
    
                            set $supercache_file '';
                            set $supercache_uri $request_uri;
    
                            if ($request_method = POST) {
                            set $supercache_uri '';
                            }
    
    # Using pretty permalinks, so bypass the cache for any query string
                            if ($query_string) {
                            set $supercache_uri '';
                            }
    
                            if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
                            set $supercache_uri '';
                            }
    
    # if we haven't bypassed the cache, specify our supercache file
                            if ($supercache_uri ~ ^(.+)$) {
                            set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
                            }
    
    # only rewrite to the supercache file if it actually exists
                            if (-f $document_root$supercache_file) {
                            rewrite ^(.*)$ $supercache_file break;
                            }
    
                            # all other requests go to WordPress
                            if (!-e $request_filename) {
                            rewrite . /index.php last;
                            }

    Donncha, could you provide translated files for Nginx in your next release? There are a lot of people who would greatly appreciate it.

  2. Donncha O Caoimh
    Member
    Posted 4 years ago #

    I can add them to the readme.txt but every time I tried using nginx it failed so I'm stuck with Apache for the time being.

    The rules above work I presume but you're missing a tutorial on how to use them. I should link to one of the many tuts online that explain it :)

  3. helmi
    Member
    Posted 4 years ago #

    I just setup some servers with nginx and php-fpm running wordpress (and wordpress mu partly). I'm basically totally happy with that setup except i'm running into trouble getting supercache working.

    I'm using the above rules and already modified some stuff but it seems like it's not working properly. I'm getting new supercache time stamps in the source every time i refresh a page - strange stuff.

  4. guvnrDOTcom
    Member
    Posted 4 years ago #

    @donncha

    "I should link to one of the many tuts online that explain it"

    well, 'hem ... I hope these are handy links for those wishing to build WP on Nginx ..

    Nginx (better than Apache) Web Server - VPS BIBLE Part 11

    And for the WP bit ..

    Set up WordPress on Nginx with Pretty URLs & WP Super Cache - VPS BIBLE Part 14

    and ..

    WordPress Setup & Updates from the Command Line - VPS BIBLE Part 15

  5. kingo55
    Member
    Posted 4 years ago #

    Hi guvnrdotcom,

    Those links didn't help - you have to pay for it.

  6. deanpence
    Member
    Posted 3 years ago #

    This configuration does not work for me unless I do not include index.php in the index directive, which causes other problems. (For example, /wp-admin/ gives a directory listing.) If I do include index.php in the index directive, it bypasses this configuration completely since an index file exists.

    This code is all over the web as "working", but I wonder if anyone's ever actually verified that it's serving static files as opposed to static files output by the plugin.

    log_subrequest on doesn't seem to log any internal redirects for me, so I put an extra field, $uri, in my log format to verify exactly what file was being used for the request:

    log_format main
            '$host : $remote_addr - $remote_user [$time_local] '
            '"$request" $status $bytes_sent '
            '"$http_referer" "$http_user_agent" '
            '"$gzip_ratio" "$uri"';

    With index.php left out index, nginx serves the static file. When it's included, it does not.

    I define my indexes at the http context, if that matters.

Topic Closed

This topic has been closed to new replies.

About this Topic