CSS/JS/Images stopped loading suddenly (probably because slash arguments)

CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Enrique Ferrater -
Number of replies: 10
Hi to everyone!,

This is my first post on this forum but I have been reading you for years and years.

Until now I have been able to manage everything by myself using the documentation and all the A+ information contained on this forum, but since a few days ago, I'm suffering a problem in my platform and I have been unable to fix it.

Maybe someone like Ken "Mighty God" Task could enlighten my burned brain and give some light in order to fix the problem.

Firstly, let me say that my platform is located here: https://www.jmformacion.com/plataforma

Currently I'm running it over:

- CentOS 8.3 and Plesk 18.0.35
- PHP-FPM served by Nginx
- PHP 7.4.18
- MariaDB 10.3.28
- Moodle 3.11+ (Build: 20210520)

I have to say that everything was working flawlesly until a few days ago that started to not load CSS, JS, and images. The only solution I have found is to disable "Slash Arguments" in Server -> HTTP section.

The exact problem I'm having was already discussed here, but I was unable to fix it:

https://moodle.org/mod/forum/discuss.php?d=373465

I have tried to configure Nginx to accept slash arguments using the official documentation (https://docs.moodle.org/311/en/Nginx#Slasharguments) adding the following to the Nginx config but modiying a few things to match my system:

location ~ ^(.+\.php)(.*)$ {
    root /var/www/vhosts/bezlab.es/jmformacion.com/public_html/;
    fastcgi_split_path_info  ^(.+\.php)(.*)$;
    fastcgi_index            index.php;
    fastcgi_pass             unix:/var/www/vhosts/system/jmoposiciones.com/php-fpm.sock;
    include /etc/nginx/mime.types;
    include                  fastcgi_params;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

I have also set "AcceptPathInfo" to "On" aswell as some PHP-FPM configuration parameters like:

[php-fpm-pool-settings]
security.limit_extensions = .php
cgi.fix_pathinfo = 1

I have tried setting "cgi.fix_pathinfo" to "0" too and all the combinations you could imagine, but nothing worked.

The funny thing is that everything was working fine without any special configuration for Nginx/PHP/FPM. I installed Plesk a few months ago and Moodle was working with almost the stock config and slash arguments enabled, but I can't tell you why, it stopped working and only solution I found was to disable slash arguments.

As I said previously, any help would be highly appreciated since I'm working with "Slash Arguments" disabled and several images are not loading since they're using "file.php/path" URL.

Thanks for everything, not just for your upcoming help but for all these years resolving Moodle issues.

Regards,
Enrique

Average of ratings: -
In reply to Enrique Ferrater

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Ken Task -
Picture of Particularly helpful Moodlers

Since you named me ... thanks ... but (am certainly *not* that 'high up') ... everything you run ... I don't.   So don't have anything specific ... cept a couple of suggestions below.

This time others who run same/similar would be your best resourses.

Suggestions:

I can load your front page with no issues.   Did use FF Console and there were a couple of lines related to 'zoom'.   What's theme?   Is it in need of an update?   What happens if making the default theme boost?

You didn't mention about caching.

Do look at your web servers error logs ... have been into systems that use Plesk before and found it to be very (maybe overly so) protective.

The typical things ... cron jobs running ok?   Those have clean up jobs as well as cache jobs.   Any of those having issues updating? removing old cached files/replacing with new?

What happens when you purge the cache .. all of it?

And I do invite others that run nginx/php-fmp, etc. to jump in here! smile

'SoS', Ken

In reply to Enrique Ferrater

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi

Were you able to solve your problem? Your "location" seems overly complicated to me.

Here is a most basic, working "default" file from Debian:
===
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;

index index.php index.html;

server_name _;

location / {
index index.php index.html
try_files $uri $uri/ =404;
}

location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
===
In reply to Visvanath Ratnaweera

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Ingeborg Muñoz Carnot -

Hello,

I would like to mention that i have a very similar situation:


  • CentOS Linux 7.9.2009 (Core)
  • Plesk Obsidian Versión 18.0.36


I have 3 moodles instances installed in the same server on different domains:


  • Domain1 --> PHP 7.4.21 | Moodle 3.8.3 (i know) | not working
  • Domain2 --> PHP 7.4.21 | Moodle 3.9.1 | Working
  • Domain3 --> PHP 7.4.21 | Moodle 3.9.2-137 (i just upgraded it to 3.10.4) | working both verions

The 3 domains have the same configuration a nginx and php-fpm level (the one by default from plesk).

Last week the first domain stop working properly, so we disabled the slash arguments and applied all the possible configurations mentioned in Moodle documentation, but none of the worked, then i checked the other domains with moodle and none of them has been affected, so i'm really lost here. Should I upgrade the first domain a version of Moodle with support for instance?


Any help or suggestion that you can provide it will be really appreaciate it.

Thanks!

In reply to Ingeborg Muñoz Carnot

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Ingeborg Muñoz Carnot -
Well I have news related to this issue.

I've created a copy of the first domain (rsync files & backup of the db) into a sub domain.

Turns out this new copy works without problems, I didn't even had to change something in the nginx configuration, only the default configuration.

I'm not really sure what is all this about, the only difference are some caches (after I tested the copy version) and the config file (modified in order to access the corresponding database and the root directory of moodle).

What else could be?
In reply to Ingeborg Muñoz Carnot

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Enrique Ferrater -
Hi Ingeborg,

No, still having this problem.

I even tried setting a new VPS with Ubuntu instead of CentOS and a fresh installation of Moodle, and problem is the same,if you activate Slash Arguments and you use Nginx+PHP-FPM, problem happens, so seems that something is broken and I have been unable to fix it.

Any help will be highly appreciated!
In reply to Visvanath Ratnaweera

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Enrique Ferrater -
Hi Visvanath!,

Thanks for the reply, unfortunately tried everything including your code, but it didn't work (check my last message below).

The funny thing is that everything worked out of the box, I mean, a fresh installation of Plesk and Moodle running over Nginx+PHP-FPM with slash arguments turned on worked flawlessly, but suddenly it stopped working, even in a fresh install and a different server distribution.

If devs wants to take a look, I can give them access to my servers without problem.

Thanks to all!
In reply to Enrique Ferrater

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi Enrique

What I know it that if you follow https://docs.moodle.org/en/Nginx carefully, copy-pasted earlier, Nginx gives back the slash arguments. Are you sure Plesk does exactly the same?

I never use Plesk, work purely in the Shell. If it worked initially and then stop working after some time, something has happened. I have no way of guessing from a distance.
In reply to Visvanath Ratnaweera

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Jason Hollowell -
Picture of Particularly helpful Moodlers
Hi Enrique, all,

I've run into a similar problem..I think and just posted an inquiry about it here today. I've been trying to document my progress but have now stopped again at this point where everything is almost perfect...with images not being served. I guess that has to do with the slash argument issue...?

Not sure if it helps but...I am using the exact code pasted earlier here in this thread:

location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        fastcgi_pass unix:/var/run/php/php-fpm.sock;
        include fastcgi_params;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

Note - php-fpm points to my current version of the socket on php7.4

So, is the split path what's causing the problem here? Anyone with more knowledge about this than me?...which is probably everyone in this thread. smile

Jason
In reply to Jason Hollowell

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Jason Hollowell -
Picture of Particularly helpful Moodlers
Hello all,

Ok, well, my problems have been resolved...problem is that I'm not sure precisely why/how.

I did two things:

1. Added --> include /etc/nginx/mime.types; to my location file.

2. Went into Moodle and purged all cashes.

Everything looks perfect now! smile I'm not sure which of the two fixed my problem but I'm glad it's fixed. Now I need to go through the methodical process of making sure my instance of Moodle is safe and secure. Being very new to Nginx, I'm afraid there may be security holes that I'm not aware of...hopefully not but it's better to be safe than sorry. wink

Cheers

Jason
Average of ratings: Useful (1)
In reply to Jason Hollowell

Re: CSS/JS/Images stopped loading suddenly (probably because slash arguments)

by Christian Toller -

Hi there,

I was fighting the same issue today, but fresh install or changing PHP versions did not change anything for me.

But I managed to find a nginx configuration the did the job:

Of course you need to replace <domain-name> 

location ~ [^/]\.php(/|$) { 
 fastcgi_split_path_info ^(.+\.php)(/.+)$;
 fastcgi_index index.php;
 fastcgi_pass unix:/var/www/vhosts/system/<domain-name>/php-fpm.sock;
 include fastcgi_params;
 fastcgi_param PATH_INFO $fastcgi_path_info;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 }

That worked for me on Plesk Obsidian with PHP 7.4.22 and 7.3.29
Please note that I still have
- php-fpm served by Apache enabled
- in the nginx settings, only "proxy mode" is enabled, intelligent handling of static files, direct handling of static files and nginx caching are disabled

Using "php-fpm served by nginx" does not seem to work, at least not with the nginx config above.

Hope it helps,

Christian Toller

tethis IT