nginx add trailing slash

gyre007 nginx-forum at nginx.us
Tue Dec 18 00:08:12 UTC 2012


I'm having troubles figuring out the following problem. Basically, we have a
jekyll blog which we decided to separate physically on the server from our
main website ie. it is not served from the main application server's root
directory. The configuration looks like this:

upstream unicorn {
  server 127.0.0.1:3000;
}

server {
      listen       4430;
      root /app/current/public;

      server_name example.com;

      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_set_header Strict-Transport-Security: "max-age=31556926;
includeSubDomains";
      proxy_redirect off;

      location ~* ^/assets {
        expires max;
        add_header Cache-Control public;
        break;
      }

      location ~* ^/admin {
        auth_basic           "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd;
        proxy_pass http://unicorn;
      }

      location ~* ^/dashboard_api {
        auth_basic           "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd;
        proxy_pass http://unicorn;
      }

      location / {
        try_files $uri/index.html $uri.html $uri @app;
      }

      location ~ /blog {
        alias /app/blog/current/;
      }

      location @app {
        auth_basic off;
        proxy_pass http://unicorn;
      }

      # Turn on maintenance mode if the maintenance template exists
      if (-f $document_root/system/maintenance.html) {
          return 503;
      }

      error_page 503 @maintenance;
      location @maintenance {
          rewrite  ^(.*)$  /system/maintenance.html last;
          break;
      }
    }

I'm talking about /blog location here. Basically, the location of the blog
files (those are just STATIC HTML files) is not in /app/current/public but
in /app/blog/current. The problem I'm having is that every time the user
tries to access the blog via the following URL: http://example.com/blog ,
the request fails and user is redirected to http://example.com:4430/blog/.
However when the user adds a trailing slash ie when he accesses
http://example.com/blog/ , all works as expected. The same thing happens
with every blog post it http://example.com/blog/post1 fails,
http://example.com/blog/post1/ succeeds. I'm trying to figure out how to
configure nginx so that the trailing slashes are added and the requests
without them will stop failing. Also I'd like to know why is the above
redirect to exmple.com:4430 happening ?? ;)

Any help would be greatly appreciates!

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,234131,234131#msg-234131



More information about the nginx mailing list