Nginx static files not being served

nginx

I am trying to run a Laravel install (a php application) when a user accesses a subdirectory of my server. I am using Nginx to serve both this and the main site (WordPress).

The directory structure is as follows:

/app
  /shop        - Laravel
  /public      - WordPress

I have my full site.conf file here

In it, I have a laravel.conf which looks like this:

location /shop {


    alias /app/shop/public;
    try_files $uri $uri/ @shop;

    autoindex on;


    location ~ \.php$ {

        try_files $uri =404;

        include /etc/nginx/includes/fastcgi_params.conf;
        fastcgi_index           index.php;
        fastcgi_split_path_info     ^(.+\.php)(/.+)$;
        fastcgi_param   PATH_INFO   $fastcgi_path_info;
        fastcgi_param   PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param   SCRIPT_FILENAME $request_filename;

        fastcgi_pass            unix:/var/run/php-fpm.sock;
        fastcgi_split_path_info     ^(.+\.php)(.*)$;
    }

}

location @shop{
    rewrite /shop/(.*)$ /shop/index.php?/$1 last;
}

If I go to mysite.dev/ it loads the WordPress site with all css and js assets, and if I go to mysite.dev/shop it loads the Laravel site. But it doesn't load any of the css files found in /app/shop/public/css/app.css (404 error).

I switched on autoindex and if I navigate to mysite.dev/shop/css it shows app.css.

What do I need to add to serve the static files?

Is the try_files block wrong?

I have been trying to work out if its something in the rest of the config that is catching requests for css and js files and routing them back through the regular public folder?

Best Answer

My guess is that the line

alias /app/shop/public;

should be

alias /app/shop;

In that way you shouldn't need the last location block.