title: Laravel - NGINX + Apache reverse proxy 404 on all routes
body: <p>i'm setting up a project in Laravel which makes use of a custom vagrant box based on Ubuntu 14.04 and which runs NGINX and Apache in a typical reverse proxy setup.</p>
  
  <p>Now, the issue is that something along the way is not registering the URL path, so when i enter <code>http://mydomain.test/hello</code> what i ultimately get is just a <code>http://mydomain.test/index.php</code> on the other end and it seems to completely forget about the route param.</p>
  
  <p>I'm using Apache 2.4.7 with Mod PHP and the Apache config is as follows.</p>
  
  <pre><code>&lt;VirtualHost 127.0.0.1:8080&gt;
      ServerName application.test
      ServerAlias www.application.test
      DocumentRoot "/home/vagrant/application/public"
  
      ErrorLog /var/log/apache2/error.log
      CustomLog /var/log/apache2/access.log combined
  
      &lt;Directory "/home/vagrant/application/public"&gt;
          Require all granted
          AllowOverride all
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>As indicated Apache is listening on Port 8080 and NGINX is listening on port 80 with the following config.</p>
  
  <pre><code>server {
      listen 80;
      server_name application.test www.application.test;
  
      root /home/vagrant/application/public;
      index index.php index.html;
  
      location / {
          try_files $uri $uri/ /index.php?$is_args$args;
      }
  
      location ~ \.php$ {
          proxy_pass http://localhost:8080;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
      }
  
      location ~ /\. {
        deny all;
      }
  }
  </code></pre>
  
  <p>I can confirm that all Laravel requirements are being fulfilled, so i have MBString, OpenSSL, etc... I can also confirm that the rewrite module is working as i can add a redirect clause to my <code>.htaccess</code> and it does get executed as expected.</p>
  
  <p>This is my <code>.htaccess</code> file.</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      &lt;IfModule mod_negotiation.c&gt;
          Options -MultiViews -Indexes
      &lt;/IfModule&gt;
  
      RewriteEngine On
  
      # Handle Authorization Header
      RewriteCond %{HTTP:Authorization} .
      RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  
      # Redirect Trailing Slashes If Not A Folder...
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} (.+)/$
      RewriteRule ^ %1 [L,R=301]
  
      # Handle Front Controller...
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Am i possibly missing something here? I've configured NGINX and PHP-FPM before but it's my first time doing it with Apache, i've gone through multiple similar questions but none of the proposed fixes has yet worked for me and that's why i ask this question.</p>
  
  <p>Thank you in advance for your help</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Some progress.</p>
  
  <p>If i set the location config for NGINX as follows</p>
  
  <pre><code>location / {
      proxy_pass http://localhost:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
  }
  </code></pre>
  
  <p>Then it works, but to the best of my knowledge then this means that even static file requests would end up proxied to Apache.</p>
  
  <p><code>location ~ \.php$</code> doesn't seem to work as the laravel pretty url doesn't end with a ".php" suffix i guess. But how would one go about making these two play nice with one another?</p>
  
  <p>The idea i guess is that you have a default location that directs to <code>index.php</code> and when that index.php file is triggered then nginx receives another HTTP request that matches your <code>php</code> location block and will proxy the request to Apache.</p>
  
  <p>The issue is that during this second request, all knowledge of the URI was lost and the URI is now just "index.php" so as far as Apache knows you're always making requests to <code>/index.php</code>.</p>
  
  <p>I still don't know how to fix it though.</p>