Support » Plugin: Jetpack by WordPress.com » What are the nginx rewrite rules for sitemap support?

  • Resolved Gwyneth Llewelyn

    (@gwynethllewelyn)


    Hello there,

    I have been struggling to get the nginx rewrite rules for Jetpack-generated sitemaps to work. Even more strangely, some of the websites I manage seem to accept the rules I’ve got, but others, using the same rules, just produce 404.

    The issue I’ve got is that most sites and articles only have rules for Yoast SEO or other plugins which produce sitemaps; Jetpack’s own rules have been ‘forgotten’ by the usually helpful nginx community.

    This is particularly true for a multisite install; no matter what rules I try to adapt, none seem to have any effect.

    So, what rules do you recommend in each case (single installs and multisite installs)?

    Thank you in advance for any help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Richard Archambault

    (@richardmtl)

    Hi! THis is the first time I’ve heard this type of question. Normally the sitemaps are supposed to “just work”. I’m curious about the 404s you’re getting. Could you post your site URLs here, so I can have a look?

    If you want it to remain private, you can also contact us via this contact form:
    https://jetpack.com/contact-support/?rel=support

    If you contact us through our form, please make sure to include a link to this thread in your message.

    Whoops. I wish I had a way to figure out when there are replies to my questions 🙂

    So here is one of the sites that does not ‘work’: https://betatechnologies.info/

    And these are the nginx rules I’ve got (the site is running W3 Total Cache and is behind CloudFlare), which are for a multisite instalation:

    index index.php;
    
    include /var/www/betatechnologies.info/web/nginx.conf;
    
            location / {
                                    try_files $uri $uri/ /index.php?$args ;
            }
    
           # Add trailing slash to */wp-admin requests.
           rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
    # for multisite with directories
    if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
    }
    
    # try this if direct access fails; it's slower; but W3TC ought to add expiry headers
    rewrite ^.*/files/(.*) /wp-includes/ms-files.php?file=$1;
    
    location ~ ^/files/(.*)$ {
            try_files /wp-content/blogs.dir/$blogid/$uri /wp-content/blogs.dir/$blogid/files/$uri /wp-includes/ms-files.php?file=$1 ;
            # access_log on; log_not_found on; expires max;
    }
    
           # Directives to send expires headers and turn off 404 error logging.
    location ~* ^.+\.(xml|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
           access_log off; log_not_found off; expires max;
    }
    
    # Deny access to any files with a .php extension in the uploads directory
    # Works in sub-directory installs and also in multisite network
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~* /(?:uploads|files)/.*\.php$ {
            deny all;
    }
    
    #avoid php readfile()
    location ^~ /blogs.dir {
            internal;
            alias /var/www/betatechnologies.info/web/wp-content/blogs.dir ;
            access_log off; log_not_found off;      expires max;
    }

    Note that the above nginx rules are just the pertinent differences from the rest of the nginx configuration… if they’re not enough to figure out what’s wrong, then I will contact you privately to show you the full configuration.

    Thanks in advance for any insights you might have!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘What are the nginx rewrite rules for sitemap support?’ is closed to new replies.