Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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; includeSubDomains";
      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 appreciated!

share|improve this question
By default nginx adds the port in redirects - the configuration parameter is port_in_redirect. Turn it off and give it a try. – cyberx86 Dec 18 '12 at 1:30
that was it! That has resolved this all! – gyre Dec 18 '12 at 2:23

The solution to this was to add

port_in_redirect off;

All works fine now.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.