title: How to redirect all Angular request to index.html in Nginx
body: <p>I have create a simple Nginx config file to server an Angular like so:</p>
  
  <pre><code>server {
    listen 80;
    listen [::]:80;
  
    root /path/to/apps/myapp/current/dist;
    access_log /path/to/apps/myapp/current/log/nginx.access.log;
    error_log /path/to/apps/myapp/current/log/nginx.error.log info;
  
    index index.html;
  
    location ^~ /assets/ {
      gzip_static on;
      expires max;
      add_header Cache-Control public;
    }
  
    location / {
      try_files $uri $uri/ =404;
    }
  }
  </code></pre>
  
  <p>And all works fine as expected. because I'm using <a href="https://github.com/angular-ui/ui-router" rel="noreferrer">Angular UI Router</a>, I'd like to forward all pages to <code>index.html</code> so Angular will take over (so a request to <code>example.com/users/new</code> will be redirect by Nginx to <code>index.html</code>, for Angular UI to handle it) for pages reloads, links, etc.</p>
  
  <p>How can I achieve this?</p>
  
  <p>I've playing around with options like:</p>
  
  <pre><code>server {
      #implemented by default, change if you need different ip or port
      #listen *:80 | *:8000;
      server_name test.com;
      return 301 $scheme://www.test.com$request_uri;
  }
  </code></pre>
  
  <p>As specified in <a href="https://stackoverflow.com/questions/10294481/how-to-redirect-a-url-in-nginx">this</a> answer. But I couldn't anything similar to work based on all requests.</p>
  
  <p>Suggestions will be much appreciated.</p>