title: laravel forge set up with angularjs
body: <p>I have just got forge up and running and serving my site and it works great.  The frontend of my site is pure angular.</p>
  
  <p>I have abstracted all of the angular aspects out of the laravel app into its own directoy on my local machine and have mapped this directory to say code/app/angular on the forge vm</p>
  
  <p>the laravel app is mapped to code/app/laravel</p>
  
  <p>lets say I have named the site awesome.app in the Homestead.yaml file and I have mapped that in my hosts file.  what I want / need is to be able to hit awesome.app and have the angular app returned and then for any calls made by the angular app to the laravel backend to be made through awesome.app/users/1 and for the laravel app to pick that up and return the correct response.  Is this possible?</p>
  
  <p>so basically awesome.app should return the static files and then the laravel app should be listening for requests on awesome.app/</p>
  
  <p>edit: I can create two sites on the vm one for the laravel app and one for the angular and then set up angular so its default base url is the laravel site but this is not ideal as it would mean removing that setting from angular before pushing to production</p>
  
  <p>edit1: I imagine that this is going to require setting up nginx to reply with the contents of the angular folder when the root domain (awesome.app) is requested and to send the rest of the requests (awesome.app/ or awesome.app/api/)to the laravel folder.  I do not know how to configure nginx at all as I was using apache until switching to homestead today.</p>
  
  <p>The ultimate goal being to keep the angular and laravel codebases seperate so that I can push just the angular app to s3 and just the laravel app to ec2 / elasticbeanstalk</p>
  
  <p>edit2:</p>
  
  <p>Thanks fideloper I finally got a chance to try out your suggestion and I think I got most of the way there.  the angular app from /home/vagrant/code/awesome/angular/build is being served correctly but the requests to the /api route are returning no input file specified.  I dug around and I dont think its a permissions issue as I can access the laravel app with a vanilla homestead setup so I imagine it is something wrong with the config</p>
  
  <p>the laravel app is in /home/vagrant/code/awesome/laravel with the index.php being in /public as normal.  as a result I changed your suggestion slightly by moving the root to the location blocks as the roots are different for / and /api.  I also tried keeping the root in the server block and adding an alias in the /api/ location block instead but this also returned no input file specified</p>
  
  <p>maybe you can see where I am going wrong?</p>
  
  <pre><code>server {
      listen 80;
      server_name awesome.app;
  
      index index.html index.htm;
  
      charset utf-8;
  
      location / {
          root /home/vagrant/Code/awesome/angular/build;
          try_files $uri $uri/ =404;
      }
  
      location /api/ {
          root /home/vagrant/Code/awesome/laravel/public;
          try_files $uri $uri/ /index.php?$query_string;
      }
  
      location ~ \/api\/index\.php$ {
          root /home/vagrant/Code/awesome/laravel/public;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
  
  fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
  
          include fastcgi_params;
  
          #This specifically sets so the /api/ portion
          #of the URL is not included
          fastcgi_param SCRIPT_FILENAME $document_root/index.php;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param ENV production;
      }
      location = /favicon.ico { access_log off; log_not_found off; }
      location = /robots.txt  { access_log off; log_not_found off; }
  
      access_log off;
      error_log  /var/log/nginx/awesome.app-error.log error;
  
      error_page 404 /index.php;
  
  sendfile off;
  
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
      }
  
      location ~ /\.ht {
          deny all;
      }
  }
  </code></pre>
  
  <p>edit3: if I remove that second location ~ .php$ location block (which I am guessing I should) I get an actual nginx 404 html page not just a 404 with no input file specified</p>
  
  <p>edit4: below config works</p>
  
  <pre><code>server {
      listen 80;
      server_name awesome.app;
      root /home/vagrant/Code/awesome/laravel/public;
      index index.html index.htm index.php;
  
      charset utf-8;
  
      location /api/ {
          try_files $uri $uri/index.php?$query_string;
      }
  
      location / {
          root /home/vagrant/Code/awesome/angular/build;
          try_files $uri $uri/ index.html;
      }
  
      location ~ \/api\/index\.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
  
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
  
          include fastcgi_params;
  
          #This specifically sets so the /api/ portion
          #of the URL is not included
          #fastcgi_param SCRIPT_FILENAME $document_root/index.php;
          #fastcgi_param PATH_INFO $fastcgi_path_info;
          #fastcgi_param ENV production;
      }
      location = /favicon.ico { access_log off; log_not_found off; }
      location = /robots.txt  { access_log off; log_not_found off; }
  
      access_log off;
      error_log  /var/log/nginx/awesome-error.log error;
  
      error_page 404 /index.php;
  
      sendfile off;
  
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+.php)(/.+)$;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
      }
      location ~ /\.ht {
          deny all;
      }
  }
  </code></pre>