Solved: Help check my nginx conf, MIME issue

Update, I have solved this by “publishing” the Livewire assets. Livewire serves the livewire.js file via the laravel app as default. Nginx cannot “see” this file and and such cannot serve it. See more below from https://github.com/livewire/livewire/issues/242#issuecomment-948054946

I was experiencing this issue “livewire.js - 404 not found” too … on the NGINX server.
The same app worked fine in an apache2 environment.
The same app also worked fine when nginx is acting as reverse proxy and just passing the data to apache2.

So i figured the issue is not any setting in the app - it is NGINX related.
And it makes absolut sense.
NGINX is a very performant web server (among other things) … this is because (next to many other reason) static files are not passed on to the php interpreter, they are served and cached directly.

What is happening with livewire (unless the assets are published and actually existing on the server, so nginx can serve them) is that the livewire.js file is build/served by the laravel app … this means PHP. But in the default nginx server configuration the request never gets that far, nginx just does not find the static js file and returns the 404 … never passing the request to the laravel app.

Cutting a long story short … there is 2 solutions to fix this issue:

1.) publish the livewire.js file any any other static file, so nginx can return them.

2.) Add one line of code to the nginx config to tell nginx to check if the static file can be found on the disk/cache if not send the request to php-fpm (in our case the index.php file) so it can be build dynamically.

Here is the code … usually you may already have a directive in your nginx config that tells nginx what to do with static files … just add this line within the directive:

try_files $uri /index.php?$query_string;

1 Like