title: nginx and laravel using alias to use api
body: <p>I'm new to nginx, so I'm a little confused about nginx, I'm using laravel framework for my frontend. In nginx, I set the root in /var/www/test/public/frontend and my api in /var/www/test/public, according to <a href="https://stackoverflow.com/questions/20426812/nginx-try-files-alias-directives">this article</a>, I tried to use alias to use my api but I failed. Here is my configuration file, please help me to see what I did wrong.</p>
  <pre><code>server {
  
          root /var/www/test/public/frontend;
          index index.html index.htm index.php;
          server_name eample.com;
          add_header X-Frame-Options &quot;SAMEORIGIN&quot;;
          add_header X-XSS-Protection &quot;1; mode=block&quot;;
          add_header X-Content-Type-Options &quot;nosniff&quot;;
          charset utf-8;
          location ~ /backend/ {
                   alias /var/www/test/public;
                   try_files $uri $uri/ /backend//backend/index.php?$query_string;
          }
          location = /favicon.ico { access_log off; log_not_found off; }
          location = /robots.txt  { access_log off; log_not_found off; }
  
          error_page 404 /index.php;
          location ~ \.php$ {
          fastcgi_pass unix:/var/run/php-fpm/www.sock;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
          }
              listen 443 ssl; # managed by Certbot
      ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
      ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
      include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
      ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  
  }
  
  server {
      if ($host = example.com) {
          return 301 https://$host$request_uri;
      } # managed by Certbot
          server_name example.com;
      listen 80;
      return 404; # managed by Certbot
  }
  </code></pre>