nginx add trailing slash

gyre007 nginx-forum at
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 {
      listen       4430;
      root /app/current/public;


      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;
      proxy_redirect off;

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

      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;

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: ,
the request fails and user is redirected to
However when the user adds a trailing slash ie when he accesses , all works as expected. The same thing happens
with every blog post it fails, 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 happening ?? ;)

Any help would be greatly appreciates!

Posted at Nginx Forum:,234131,234131#msg-234131

More information about the nginx mailing list