title: Multiple angular 2 apps and /api on same host with nginx
body: <p>I'm trying to achieve this goal with nginx configuration:</p>
  
  <pre><code>mydomain.com/api        should serve the php API
  mydomain.com/login      should serve an angular 2 app
  mydomain.com/dashboard  should serve another angular 2 app
  </code></pre>
  
  <p>The nginx.conf I post below works fine except for this (which is the problem i need help fixing):</p>
  
  <p>When the user visits a route in angular like <strong>mydomain.com/dashboard/forms</strong> then the url is rewritten like this <strong>mydomain.com/dashboard/dist/forms</strong></p>
  
  <p>Here is the code tree:</p>
  
  <pre><code>├── mydomain.com
  │   ├── app           // slim project
  │   │   └── ...
  │   ├── public
  │   │   ├── dashboard // anuglar project
  |   |   |   └── dist
  │   │   └── login     // angular project
  |   |       └── dist
  </code></pre>
  
  <p>And here is the server block I use:</p>
  
  <pre><code>server {
  
    listen 80;
    server_name mydomain.com;
  
    error_log /home/test/code/mydomain.com/error.log;
    access_log /home/test/code/mydomain.com/access.log;
    root /home/test/code/mydomain.com/public/;
  
    sendfile on;
    rewrite_log on;
    include  /etc/nginx/mime.types;
  
    gzip on;
  
    location ~ ^/(assets|bower_components|scripts|styles|views) {
      expires     31d;
      add_header  Cache-Control public;
    }
  
    ############################################################################
    #                             D A S H B O A R D
    ############################################################################
  
    location /dashboard/ {
      alias /home/test/code/mydomain.com/public/dashboard/dist/;
      try_files $uri $uri/ /index.html =404;
    }
  
    ############################################################################
    #                                L O G I N
    ############################################################################
  
    location /login/ {
      alias /home/test/code/mydomain.com/public/login/dist/;
      try_files $uri $uri/ /index.html =404;
    }
  
    ############################################################################
    #                                 A P I
    ############################################################################
  
    location ~ ^/api/(.*)$ {
      alias /home/test/code/mydomain.com/public;
      try_files $1 $1/ @php;
      index index.php;
    }
  
    location @php {
      fastcgi_split_path_info ^(/api)(/.*)$;
      fastcgi_pass localhost:9000;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME /home/test/code/mydomain.com/public/index.php;
      fastcgi_param REQUEST_URI $fastcgi_path_info;
      fastcgi_read_timeout 900;
    }
  }
  </code></pre>
  
  <p>What should I change so that the "/dist" doesn't get written in the url?</p>