# Nginx add trailing slash

**URL:** <https://www.ruby-forum.com/t/nginx-add-trailing-slash/225147>\
**Category:** NGINX\
**Created:** [December 18, 2012, 1:08am UTC](https://www.ruby-forum.com/t/nginx-add-trailing-slash/225147 "2012-12-18T01:08:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [December 18, 2012, 1:08am UTC](https://www.ruby-forum.com/t/nginx-add-trailing-slash/225147/1 "2012-12-18T01:08:32Z")

</div>

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](http://example.com/blog)  
,  
the request fails and user is redirected to  
[http://example.com:4430/blog/](http://example.com:4430/blog/).  
However when the user adds a trailing slash ie when he accesses  
[http://example.com/blog/](http://example.com/blog/) , all works as expected. The same thing happens  
with every blog post it [http://example.com/blog/post1](http://example.com/blog/post1) fails,  
[http://example.com/blog/post1/](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](http://exmple.com:4430) happening ?? 😉

Any help would be greatly appreciates!

Posted at Nginx Forum:

> **[nginx add trailing slash](https://forum.nginx.org/read.php?2,234131,234131#msg-234131)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![gyre007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecccb3/32.png) [@gyre007](https://www.ruby-forum.com/u/gyre007)\
**Post date:** [December 18, 2012, 9:30am UTC](https://www.ruby-forum.com/t/nginx-add-trailing-slash/225147/2 "2012-12-18T09:30:18Z")

</div>

Hi,

you may want to have a look into the `port_in_redirect` directive (  
[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#port_in_redirect)).

Regards,  
Christian

2012/12/18 gyre007 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
