title: How to fix nginx 404 not found for a Laravel app?
body: <p>All my routes got <code>404</code> Not Found. I can open Laravel page if I access the <code>localhost/mylaravel</code>, but if I access <code>localhost/mylaravel/login</code>, I got 404 not found page. If I change route home on /home and access it, I got 404 not found.</p>
  
  <p>I'm using Laravel Framework 5.6.33</p>
  
  <p>This is my routes file:</p>
  
  <pre><code>&lt;?php
  
  Route::get('/', function () {
      return view('home/home');
  });
  Route::get('/login', function () {
      return view('login/login');
  });
  </code></pre>
  
  <p>And this is my nginx config at <code>/etc/nginx/sites-available/default</code></p>
  
  <pre><code>server {
      listen 80 default_server;
      listen [::]:80 default_server;
      server_name localhost;
      charset utf-8;
      root /var/www/html/;
      index index.php index.html index.htm index.nginx-debian.html;
  
      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
      location /mylaravel/ {
           try_files $uri $uri/ /index.php?$query_string;
          }
  
      location ~ \.php$ {
      try_files $uri $uri/ =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_pass    unix:/var/run/php/php7.2-fpm.sock;
      fastcgi_index   index.php;
      include fastcgi_params;
      }
  
      location ~ /\. {
          deny all;
      }
  
      location ~* ^.+\.(css|js|jpg|jpeg|gif|png|txt|ico|swf|xml|woff|woff2|ttf|mp3|svg|csv|xls|xlsx|eot|otf)$ {
      access_log off;
      expires modified +90d;
      }
  }
  </code></pre>