0

I have seen a couple of similar issues, but none of the solutions/reasons helped me. I installed Magento 2.4; tried it switch it to default and developer modes, forced it to compile and deploy static content (just in case, it says there is no need for that, but I tried just for sure; cash was flushed) and it seems like it does everything correctly, I see created files in pub directory. When the browser requests them it gets 404, mod_rewrite for Apache is enabled, I checked if I change .htaccess it changes site behavior and Apache shows it is enabled it CLI. So it has to be fine. I have Nginx installed as a proxy, but there are no problems with other CMS such as WordPress. It is only a Magento issue which I can't solve. I use it in local environment in Virtual Box with Ubuntu 20.04. Nginx has following rule for CSS/JS location ~ .*\.(js|css)?$ { expires 7d; access_log off; } Apache does not have any specific instructions for them. I get only image /frontend/Magento/luma/ru_RU/images/logo.svg Do you have any ideas, what could be wrong?

2 Answers 2

0

It kind of sounds like you've deleted the .htaccess file out of pub/static. That will cause 404s for javascript and css.

If that file is missing recreate it from the contents here: https://github.com/magento/magento2/blob/2.4-develop/pub/static/.htaccess

And see if that helps. Then be careful not to delete that folder, just its contents, as needed.

1
  • No, both my .htaccess in pub and pub/static are OK, I compared it with github's analogs they are the same. I cleared .htaccess in pub/static and lost my only image I get. I returned it to it's initial state and got my image back. But there is still no CSS and JS.
    – NIck
    Commented Nov 3, 2021 at 6:16
0

This problem is related to nxinx config. Any attempt to set caching rules in nginx for js/css breaks functionality. I believe this issue may be often seen on preconfigured hosts and server setups. You should remove rules such as location ~ .*\.(js|css)?$ { expires 7d; access_log off; } I have tried different approaches including checking if file exists, but it did not work for me, if I leave caching options, nothing comes through. If anyone know how to set it up correctly please let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.