Welcome! Log In Create A New Profile

Advanced

nginx add trailing slash

December 17, 2012 07:08PM
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!
Subject Author Posted

nginx add trailing slash

gyre007 December 17, 2012 07:08PM

Re: nginx add trailing slash

hexa December 18, 2012 03:30AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 117
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready