title: Nginx Configuration for Wordpress AND Laravel Application
body: <p>I'm trying to get my Wordpress blog hosted on <code>blog.domain.com</code> to work on <code>domain.com/blog</code>.</p>
  <p>I have been able to do this with <code>proxy_pass</code> successfully but the issue is certain scripts such as the login page for admins (/wp-login.php) does not work - it gives me <code>File not found.</code>. I have isolated the issue to my Laravel applications FastCGI setup in my Nginx configuration. When I comment it out, my blog works but then my Laravel app is inaccessible. I've been trying different configurations but I have little knowledge with Nginx.</p>
  <pre><code>server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      server_name mydomain.com;
      server_tokens off;
      root /home/appfolder/mydomain.com/public;
  
  ...
  
  ...
  
      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;;
  
      index index.html index.htm index.php;
  
      charset utf-8;
  
      # FORGE CONFIG (DO NOT REMOVE!)
      include forge-conf/mydomain.com/server/*;
  
      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
  
      
  # WHEN I COMMENT OUT THIS BLOCK, BLOG WORKS BUT LARAVEL BREAKS
      location ~ \.php$ {
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_pass unix:/var/run/php/php7.4-fpm-mydomain.sock;
           fastcgi_index index.php;
           include fastcgi_params;
      }
      
      
      location /blog {
          proxy_redirect     off;
          proxy_set_header   Host $host;
          proxy_pass  https://blog.mydomain.com;
      }
      location /blog/wp-content {
          proxy_pass  https://blog.mydomain.com/wp-content;
      } 
      location /blog/wp-includes {
          proxy_pass https://blog.mydomain.com/wp-includes;
      }
      location /blog/wp-content/uploads {
          proxy_pass https://blog.mydomain.com/wp-content/uploads;
      }
      location /blog/wp-login.php {
          proxy_pass https://blog.mydomain.com/wp-login.php;
      }
      location /blog/wp-admin {
          proxy_pass https://blog.mydomain.com/wp-admin;
      }
      location /bitnami {
          proxy_pass https://blog.mydomain.com/bitnami;
      }
      location /mod_pagespeed_beacon {
          proxy_pass https://blog.mydomain.com/mod_pagespeed_beacon;
      }
      
      
  
      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/mydomain.com-error.log error;
  
      error_page 404 /index.php;
  
  
  
      location ~ /\.(?!well-known).* {
          deny all;
      }
  }
  
  ...
  </code></pre>
  <p>Hosted on an Ubuntu server managed by Laravel Forge. Any ideas?</p>
  <p><strong>Update:</strong> As per Richards answer, I have started getting it working a little bit but I need to add rules for all files which doesn't seem efficient.</p>
  <p>I'm trying to get all .PHP files related to Wordpress (after <code>/blog/</code>) to be forwarded to the proxy. I have tried:</p>
  <pre><code>    location ~ /blog/wp-admin/(\d+) {
          add_header X-debug-message &quot;$1&quot;;
          proxy_pass https://blog.mydomain.com/wp-admin/$1;
      }
  </code></pre>
  <p>But this doesn't seem to work.</p>