title: Extending Nginx config on Beanstalk doesn't rewrite urls properly
body: <p>I have an existing Laravel API application running on Beanstalk. It's been lagging in updates on EBS, so currently I'm in the process of upgrading the platforms and CI/CD for this app. There one remaining problem I'm running into, which leaves me scratching my head at the 'but it <em>should</em> work'-level.</p>
  <p><strong>What I want</strong></p>
  <p>All URLs containing <a href="https://example.com/index.php/endpoint" rel="nofollow noreferrer">https://example.com/index.php/endpoint</a> to be redirected to <a href="https://example.com/endpoint" rel="nofollow noreferrer">https://example.com/endpoint</a> and show the same content as <a href="https://example.com/index.php/endpoint" rel="nofollow noreferrer">https://example.com/index.php/endpoint</a> would (incl. subsequent the URL's slugs)</p>
  <p><strong>How I'm trying to do this</strong></p>
  <p>Due to <a href="https://stackoverflow.com/questions/21687288/nginx-redirect-loop-remove-index-php-from-url">this wonderful answer</a> by <a href="https://stackoverflow.com/users/1122270/cnst">cnst</a>, I have the configuration below that seems to work for many (incl. some other online sources).</p>
  <pre><code>server{
      index index.php;
  
      if ($request_uri ~* &quot;^(.*/)index\.php/*(.*)$&quot;) {
          return 301 $1$2;
      }
  
      location / {
          try_files $uri $uri/ /index.php?$query_string;
  
          # Remove from everywhere index.php
          if ($request_uri ~* &quot;^(.*/)index\.php(/?)(.*)&quot;) {
              return 301 $1$3;
          }
      }
  
      if (!-d $request_filename) {
          rewrite ^/(.+)/$ /$1 permanent;
      }
  
      if ($request_uri ~* &quot;\/\/&quot;) {
          rewrite ^/(.*) /$1 permanent;
      }
  }
  </code></pre>
  <p>I'm putting this configuration in a file located at <code>my_project/.platform/nginx/conf.d/proxy.conf</code>, which according to <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html" rel="nofollow noreferrer">AWS' documentation</a>, should upload with the project and <em>extend</em> the nginx configuration. As far as I can tell, it does pick it up, since any typo will result in an error after <code>eb deploy</code>. I can also see on the server it has been added to <code>/etc/nginx/conf.d/proxy.conf</code>.</p>
  <p><strong>The Problem</strong></p>
  <p>Even though the extending proxy.conf is being deployed and the configuration in it seems to be picked up, the application won't pick up the rewrite and leave the application URLs running with the <code>index.php</code> instead of the rewrite.</p>
  <ul>
  <li><code>https://example.com/index.php/endpoint</code> → works</li>
  <li><code>https://example.com/endpoint</code> → results in a server generated 404</li>
  <li>Nginx logs show <code>2021/02/12 14:23:24 [error] 7523#0: *35 open() &quot;/var/www/html/public/api&quot; failed (2: No such file or directory)</code> which tells me it has searched for a file and never tried running it through <code>index.php</code>.</li>
  </ul>
  <p><strong>The Questions</strong></p>
  <ul>
  <li>What am I missing in my configuration?</li>
  <li>Or is it something about EBS that I overlooked or misunderstood?</li>
  <li>Is the <code>index.php</code> angry since I'm trying to hide its face from public view?</li>
  </ul>