I want to add pretty URLS in Angular UI-router. I have Nginx + Unicorn over a Rails app with Angular JS as the front-end.
I want to have pretty URLS like mysite/a/b/c, no '#' and no hashbang. When I change the location of nginx to:
server {
server_name yoursite.com;
root /path/to/app;
location / {
try_files $uri $uri/ @unicorn;
}
}
Unicorn will throw this error:
directory index of "/path/to/app" is forbidden
Any idea on how to setup nginx to redirect? Giving chmod to my app path isn't a good solution I believe..
Edit: The issue is that with try_files $uri/index @unicorn, it works e.g. url.com/a/b. But when I refresh, it automatically redirects me to root url.com. UI-router suggests try_files $uri $uri/ /index.html, but when I do this I get an access denied by nginx. The folder /path/to/app belongs to user 'deploy', so it's not a chmod issue..
/path/to/app
as set in theroot
directive. At least in my case, I run my Rails/Unicorn application from the same user that is the owner of those files. – steve kleinmina
to manage my deploys but I think it is similar toChef
. When I deploy,mina
pulls my files from git and builds them in/home/myapp/app/current/public
and makes usermyapp
owner. This is my public Rails directory - it has assets plus some static error page files like 404.html - and is where my NGINX root directive points. To start/restart the application, I run/etc/init.d/unicorn.myapp
which, among other things, performs su - myapp to run Unicorn under myapp. The Rails router handles routing of requests from this public directory to app/controllers etc. – steve klein