Skip to content

Instantly share code, notes, and snippets.

@mallowigi
Created June 26, 2014 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mallowigi/2fb57a111dd82665268b to your computer and use it in GitHub Desktop.
Save mallowigi/2fb57a111dd82665268b to your computer and use it in GitHub Desktop.

A Working configuration to setup HTML5 push-state routing in your AngularJS app with Nginx as your web server.

app.config(function (...) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix = '!';
...
});
...
<head>
<!--use absolute paths for file refs-->
<link rel="stylesheet" href="/styles/main.css">
...
<base href="/">
...
</head>
...
server {
listen 80;
set $host_path "/path/to/your/app";
root $host_path;
index index.html;
# SEO
if ($args ~ "_escaped_fragment_=/?(.+)") {
set $path $1;
rewrite ^ /snapshots/$path last;
}
# Re-route nested routes through index
location / {
try_files $uri $uri/ /index.html =404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment