Skip to content

8 Comments

  1. lloan alas
    June 27, 2019 @ 12:41 am

    Will this work with subdirectory sites? meaning, example.com/subdirectory

    Reply

    • Dave H.
      June 27, 2019 @ 7:16 pm

      Hi – yes – it should do. Let me know if it doesn’t work for you and I’ll investigate.

      Reply

  2. Eric
    December 19, 2019 @ 4:29 pm

    I have been using your config stacks for a few websites and had no issues but I cannot get the nginx rewrites to actually work on this one site. I have gone and looked at all configs and setup and find no reason it shouldn’t work but the sitemaps only show on /?sitemap=1 then the sub sitemaps will 404 on me. What am i doing wrong here?

    Reply

    • Dave H.
      December 19, 2019 @ 6:29 pm

      I’m not sure – can you share your nginx config file? Maybe a different rule is being matched first?

      I presume you restarted nginx after adding the sitemap rewrite rules?

      Reply

      • Eric Schroeder
        December 27, 2019 @ 6:36 pm

        Any update on my configs?

        Reply

        • Dave H.
          January 15, 2020 @ 7:15 pm

          Replied – sorry about delay – looks like you have 2 missing }’s

          Reply

  3. Eric Schroeder
    December 19, 2019 @ 7:17 pm

    Yep restarted service and zippo!

    Here is the conf:

    # This config file uses nginx fastcgi-cache
    fastcgi_cache_path /var/www/cache/evolutionit levels=1:2 keys_zone=evolutionit:100m inactive=60m;

    server {
    listen 80;
    server_name evolutionitservice.com;

    root /var/www/evolutionit;

    index index.php index.htm index.html;

    access_log /var/log/nginx/evolutionit_access.log;
    error_log /var/log/nginx/evolutionit_error.log;
    include snippets/gzip.conf
    #include snippets/yoast-sitemaps.xml;
    include snippets/acme-challenge.conf;

    # Rewrites for Yoast SEO XML Sitemap EJS
    rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

    location ~ ([^/]*)sitemap(.*).x(m|s)l$ {
    ## this rewrites sitemap.xml to /sitemap_index.xml
    rewrite ^/sitemap.xml$ /sitemap_index.xml permanent;
    ## this makes the XML sitemaps work
    rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 last;
    rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    ## The following lines are optional for the premium extensions
    ## News SEO
    rewrite ^/news-sitemap.xml$ /index.php?sitemap=wpseo_news last;
    ## Local SEO
    rewrite ^/locations.kml$ /index.php?sitemap=wpseo_local_kml last;
    rewrite ^/geo-sitemap.xml$ /index.php?sitemap=wpseo_local last;
    ## Video SEO
    rewrite ^/video-sitemap.xsl$ /index.php?xsl=video last;
    }

    # Exclusions
    include snippets/exclusions.conf;

    # Security
    include snippets/security.conf;

    # Static Content
    include snippets/static-files.conf;

    # Fastcgi cache rules
    include snippets/fastcgi-cache.conf;

    include snippets/limits.conf;

    include snippets/nginx-cloudflare.conf;

    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
    try_files $uri =404;
    include snippets/fastcgi-params.conf;

    fastcgi_pass unix:/run/php/php7.3-fpm.sock;

    # Skip cache based on rules in snippets/fastcgi-cache.conf.
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;

    # Define memory zone for caching. Should match key_zone in fastcgi_cache_path above.
    fastcgi_cache evolutionit;

    # Define caching time.
    fastcgi_cache_valid 60m;
    #increase timeouts
    fastcgi_read_timeout 6000;
    fastcgi_connect_timeout 6000;
    fastcgi_send_timeout 6000;
    proxy_read_timeout 6000;
    proxy_connect_timeout 6000;
    proxy_send_timeout 6000;
    send_timeout 6000;

    #these lines should be the ones to allow Cloudflare Flexible SSL to be used so the server does not need to decrypt SSL
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Real-IP $remote_addr;

    server {
    listen 443 ssl default_server;
    server_name evolutionitservice.com;

    root /var/www/evolutionit;

    index index.php index.htm index.html;
    #Include Yoast Sitemap Config
    # include snippets/yoast-sitemaps.xml;

    # Rewrites for Yoast SEO XML Sitemap EJS
    rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

    location ~ ([^/]*)sitemap(.*).x(m|s)l$ {
    ## this rewrites sitemap.xml to /sitemap_index.xml
    rewrite ^/sitemap.xml$ /sitemap_index.xml permanent;
    ## this makes the XML sitemaps work
    rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 last;
    rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    ## The following lines are optional for the premium extensions
    ## News SEO
    rewrite ^/news-sitemap.xml$ /index.php?sitemap=wpseo_news last;
    ## Local SEO
    rewrite ^/locations.kml$ /index.php?sitemap=wpseo_local_kml last;
    rewrite ^/geo-sitemap.xml$ /index.php?sitemap=wpseo_local last;
    ## Video SEO
    rewrite ^/video-sitemap.xsl$ /index.php?xsl=video last;
    }
    access_log /var/log/nginx/evolutionit_ssl_access.log;
    error_log /var/log/nginx/evolutionit_ssl_error.log;

    #once you have SSL certificates using LetsEncrypt you can alter the paths in the two lines below to reflect your domain and uncomment the lines by removing the leading # symbol
    #ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    #ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;

    # Exclusions
    include snippets/exclusions.conf;

    # Security
    include snippets/security.conf;

    # Static Content
    include snippets/static-files.conf;

    # Fastcgi cache rules
    include snippets/fastcgi-cache.conf;

    include snippets/limits.conf;

    include snippets/nginx-cloudflare.conf;

    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
    try_files $uri =404;
    include snippets/fastcgi-params.conf;

    fastcgi_pass unix:/run/php/php7.3-fpm.sock;

    # Skip cache based on rules in snippets/fastcgi-cache.conf.
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;

    # Define memory zone for caching. Should match key_zone in fastcgi_cache_path above.
    fastcgi_cache evolutionit;

    # Define caching time.
    fastcgi_cache_valid 60m;
    #increase timeouts
    fastcgi_read_timeout 6000;
    fastcgi_connect_timeout 6000;
    fastcgi_send_timeout 6000;
    proxy_read_timeout 6000;
    proxy_connect_timeout 6000;
    proxy_send_timeout 6000;
    send_timeout 6000;

    #these lines should be the ones to allow Cloudflare Flexible SSL to be used so the server does not need to decrypt SSL if you wish
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-NginX-Proxy true;

    Reply

    • Dave H.
      January 15, 2020 @ 7:15 pm

      It looks like your first server {} block for port 80 does not have the closing brace. ‘}’ is missing.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *