Access to plugin assets (js and img work fine, css returns 404)

CakePHP 3.8 deployed on NGINX server on Ubuntu 16.04.

Created plugin using bin/cake bake plugin Ocean. Can access all assets on /ocean/js, and /ocean/img, but when trying to access /ocean/css the *.css files return error 404.

I SSH’ed to the server and created couple of test files alongside the *.css and all of them I can access through https://example.com/ocean/css/whateverfile.txt, as long as they’re not CSS files. I have no problems accessing CSS files in the main app location (i.e. https://example.com/css), but plugin CSS don’t work. I tried creating couple more plugins with the same results.

I checked NGINX server configuration, but suspect this is somehow related to my app configuration…? routes? re-writes…?

Any help will be greatly appreciated!

Thanks in advance,
Robert

Hii there,

First of all, welcome to the forums, I hope you’ll have a nice time baking with us :slight_smile:

Anyhow, back to the question.
Are you getting a CakePHP error or a Nginx error?
If it’s a CakePHP error, it should say something along the lines of: “Missing controller 'css'”, if it’s an Nginx error, well… you should get an nginx page saying “404”.

If you are getting an CakePHP error, that means Nginx can’t find the file itself and just hands it off to CakePHP to handle.
If you are getting an Nginx error, that means it both can’t find it and doesn’t hand it off to CakePHP to handle either.

My own Nginx config looks a bit like this:

location / {
    try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    fastcgi_intercept_errors on;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
1 Like

Thanks for the warm welcome and for the advice. Appreciate it!

Turns out it was NGINX server configuration file that was causing the problem. I failed to add in the question that my plugin triggers theme (plugin) based on the domain the app is served from. In my NGINX configuration I had some rewrite rules from earlier renditions of CakePHP, which were causing the 404 errors.

Thanks again!
Robert

1 Like

I’m glad it got sorted out.
If you encounter any more issues later down the road, feel free to open up another thread!