Skip to content
Snippets Groups Projects
nginx.vh.default.template.conf 3.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • FORESTIER Fabien's avatar
    FORESTIER Fabien committed
    # nginx.vh.default.conf  --  docker-openresty
    #
    # This file is installed to:
    #   `/etc/nginx/conf.d/default.conf`
    #
    # It tracks the `server` section of the upstream OpenResty's `nginx.conf`.
    #
    # This config (and any other configs in `etc/nginx/conf.d/`) is loaded by
    # default by the `include` directive in `/usr/local/openresty/nginx/conf/nginx.conf`.
    #
    # See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
    #
    
    ##
    # Cache Settings
    ##
    proxy_cache_path /var/cache/nginx/cache keys_zone=elasticsearch:10m inactive=1d max_size=10g use_temp_path=off;
    
    server {
        listen       80;
        server_name  localhost;
    
        #charset koi8-r;
    
    
        access_log /dev/stdout my_log_format;
        error_log /dev/stderr;
    
    FORESTIER Fabien's avatar
    FORESTIER Fabien committed
    
        location /_search {
            if ($http_x_consumer_username = '') {
    
                set_by_lua_block $elasticsearch_alias { return ngx.md5('${ANONYMOUS_USER}') }
    
                # set_by_lua_block $elasticsearch_alias { return '${ANONYMOUS_USER}' }
            }
    
            if ($http_x_consumer_username != '') {
    
                set_by_lua_block $elasticsearch_alias { return ngx.md5(ngx.var.http_x_consumer_username) }
    
                # set_by_lua_block $elasticsearch_alias { return ngx.var.http_x_consumer_username }
                # set_by_lua_block $elasticsearch_alias { return '${ANONYMOUS_USER}' }
            }
    
            set_by_lua_block $ghost_alias {
    
                if ngx.var.http_x_consumer_groups == nil then
                    return ",${PUBLISHED_POSTS_ALIAS},${PUBLISHED_PAGES_ALIAS}"
    
                elseif string.find( ngx.var.http_x_consumer_groups, "${GHOST_EDITORS_GROUPNAME}" ) ~= nil then
                    return ",${PUBLISHED_POSTS_ALIAS},${DRAFT_POSTS_ALIAS},${PUBLISHED_PAGES_ALIAS},${DRAFT_PAGES_ALIAS}"
    
                else
                    return ",${PUBLISHED_POSTS_ALIAS},${PUBLISHED_PAGES_ALIAS}"
                end
    
            }
    
            set $aliases '${elasticsearch_alias}${ES_ALIAS_SUFFIX}${ghost_alias}';
            rewrite ^/(.*)$ /$aliases/$1 break;
    
            # FOR DEBUG PURPOSES ONLY
            add_header X-Consumer-Username    $http_x_consumer_username;
            add_header X-Consumer-Groups      $http_x_consumer_groups;
            add_header X-Anonymous-Consumer   $http_x_anonymous_consumer;
            add_header X-Elasticsearch-Alias  $elasticsearch_alias;
            add_header X-Ghost-Alias          $ghost_alias;
            add_header X-Aliases              $aliases;
            #
    
            # cache ------------------------------------------
            proxy_cache elasticsearch;
    
            proxy_buffer_size 8192;
    
    FORESTIER Fabien's avatar
    FORESTIER Fabien committed
            proxy_cache_valid 200 302 1m;
            proxy_cache_valid 404 1m;
            proxy_cache_background_update on;
            proxy_cache_use_stale updating;
            proxy_cache_revalidate on;
            proxy_cache_methods GET HEAD POST;
            proxy_cache_key "$aliases|$request_uri|$request_body";
            proxy_cache_bypass $http_nocache;
            add_header X-Cache-Status $upstream_cache_status;
            # ------------------------------------------------
    
            proxy_http_version 1.1;
            proxy_set_header Connection "Keep-Alive";
            proxy_set_header Proxy-Connection "Keep-Alive";
            proxy_pass ${ES_UPSTREAM_SERVER};
    
        }
    }