≡

wincent.dev

  • Products
  • Blog
  • Wiki
  • Issues
You are viewing an historical archive of past issues. Please report new issues to the appropriate project issue tracker on GitHub.
Home » Issues » Bug #1764

Bug #1764: Static file indexes broken

Kind bug
Product wincent.dev
When 2011-01-08T19:20:54Z
Status closed
Reporter Greg Hurrell
Tags no tags

Description

Right now links like:

  • https://wincent.dev/products/wikitext/doc
  • https://wincent.dev/products/wikitext/doc/

Aren't working. The slashless version does correctly redirect to the slashed version, but ends up returning a 404.

This works:

  • https://wincent.dev/products/wikitext/doc/index.html

Not sure if this was caused by the move to the nginx 0.8.x series, or some other tweak that was made to the config file.

Comments

  1. Greg Hurrell 2011-01-08T21:03:07Z

    It was a mistake in the config file (specifically, we were rewriting to $1$index_filename instead of $1$index_filename$cache_extension in one place). The relevant section of the config file now looks like this:

        # rewrite all requests to *.example.com back to example.com
        if ($host != example.com) {
          rewrite ^(.*) https://example.com$1 permanent;
        }
    
        # serve static content without hitting Rails
        # this also bypasses our maintenance page check
        location ~ /(images|javascripts|stylesheets)/ {
          expires 72h;
        }
    
        location /system/maintenance.html {
          # always allow access to this file; explained here:
          # http://www.ruby-forum.com/topic/141251
        }
    
        location / {
          if (-f $document_root/system/maintenance.html) {
            error_page 503 /system/maintenance.html;
            return 503;
          }
    
          # cached pages: only for GET requests
          set $cache_extension '';
          if ($request_method = GET) {
            set $cache_extension '.html';
          }
    
          if (-f $request_filename) {
            break;
          }
    
          set $index_filename 'index';
          if (-f $request_filename$index_filename$cache_extension) {
            # URI has trailing slash
            rewrite (.*) $1$index_filename$cache_extension break;
          }
    
          if (-f $request_filename/$index_filename$cache_extension) {
            # URI has no trailing slash
            rewrite (.*) $1/ permanent;
          }
    
          if (-f $request_filename$cache_extension) {
            rewrite (.*) $1.html break;
          }
    
          if (-f $static_root$uri) {
            root $static_root;
            break;
          }
    
          if (-f $static_root${uri}index.html) {
            # URI has trailing slash
            root $static_root;
            rewrite (.*) $1$index_filename$cache_extension break;
          }
    
          if (-f $static_root$uri/index.html) {
            # URI has no trailing slash
            rewrite (.*) $1/ permanent;
          }
    
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X_FORWARDED_PROTO https;
          proxy_max_temp_file_size 0;
          if (!-f $request_filename) {
            proxy_pass http://unicorn;
            break;
          }
        }
  2. Greg Hurrell 2011-01-08T21:07:08Z

    Status changed:

    • From: new
    • To: closed
Add a comment

Comments are now closed for this issue.

  • contact
  • legal

Menu

  • Blog
  • Wiki
  • Issues
  • Snippets