apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-site
data:
  default.conf: |
    fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    
    upstream php {
            server unix:/tmp/php-cgi.socket;
            server 127.0.0.1:9000;
    }
    
    server {
            listen 8080;
            ## Your only path reference.
            root /var/www/html;
            ## This should be in your http block and if it is, it's not needed here.
            index index.php;
    
            set $skip_cache 0;
    
            # POST requests and URLs with a query string should always go to PHP
    
            if ($request_method = POST) {
                set $skip_cache 1;
            }
    
            if ($query_string != "") {
                set $skip_cache 1;
            }
    
            # Don't cache URIs containing the following segments
    
            if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
                set $skip_cache 1;
            }
    
            # Don't use the cache for logged-in users or recent commenters
            if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
                set $skip_cache 1;
            }
    
            location = /favicon.ico {
                    log_not_found off;
                    access_log off;
            }
    
            location = /robots.txt {
                    deny all;
                    log_not_found off;
                    access_log off;
            }
    
            location / {
                    # This is cool because no php is touched for static content.
                    # include the "?$args" part so non-default permalinks doesn't break when using query string
                    try_files $uri $uri/ /index.php?$args;
            }
    
            location ~ \.php$ {
                    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                    include fastcgi.conf;
                    fastcgi_intercept_errors on;
                    fastcgi_pass php;
                    fastcgi_cache_bypass $skip_cache;
                    fastcgi_no_cache $skip_cache;
                    fastcgi_cache WORDPRESS;
                    fastcgi_cache_valid  1m;
            }
    
            location ~* \.(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)$ {
                    expires max;
                    log_not_found off;
                    access_log off;
            }
    }
