Grav can't load CSS and JS on webserver

I’ve just installed Grav on my DigitalOcean droplet. Almost everything is working.

However, it’s not loading any JS nor CSS. This is the message I get in the console :

Same thing if I look at the source :

I checked in my Grav’s arborescence and the paths do exist, so I’m wondering what might be the problem.

Thx

p.s. if it can help, here’s my grav file in /etc/nginx/sites-available :

server {
    #listen 80;
    index index.html index.php;

    ## Begin - Server Info
    root /home/grav/www/html;
    server_name localhost;
    ## End - Server Info

    ## Begin - Index
    # for subfolders, simply adjust:
    # `location /subfolder {`
    # and the rewrite to use `/subfolder/index.php`
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    ## End - Index

    ## Begin - Security
    # deny all direct access for these folders
    location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
    # deny running scripts inside core system folders
    location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat|css|js)$ { return 403; }
    # deny running scripts inside user folder
    location ~* /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat|css|js)$ { return 403; }
    # deny access to specific files in the root folder
    location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }
    ## End - Security

    ## Begin - PHP
    location ~ \.php$ {
        # Choose either a socket or TCP/IP address
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        # fastcgi_pass unix:/var/run/php5-fpm.sock; #legacy
        # fastcgi_pass 127.0.0.1:9000;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }
    ## End - PHP
}

And the nginx.conf in /home/grav/www/html/webserver-configs :

server {
    #listen 80;
    index index.html index.php;

    ## Begin - Server Info
    root /home/USER/www/html;
    server_name localhost;
    ## End - Server Info

    ## Begin - Index
    # for subfolders, simply adjust:
    # `location /subfolder {`
    # and the rewrite to use `/subfolder/index.php`
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    ## End - Index

    ## Begin - Security
    # deny all direct access for these folders
    location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
    # deny running scripts inside core system folders
    location ~* /(system|vendor)/.*\.(txt|xml|md|html|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
    # deny running scripts inside user folder
    location ~* /user/.*\.(txt|md|json|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
    # deny access to specific files in the root folder
    location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }
    ## End - Security

    ## Begin - PHP
    location ~ \.php$ {
        # Choose either a socket or TCP/IP address
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        # fastcgi_pass unix:/var/run/php5-fpm.sock; #legacy
        # fastcgi_pass 127.0.0.1:9000;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }
    ## End - PHP
}

@douxdoux-1312, Cross-posting a question here on Discourse and within 30 minutes on StackOverflow is not really appreciated.

It shows a lack of respect for the time and effort spend by volunteers on both forums. In the end, the time and effort spend on one forum is just wasted.

You might consider removing one of the duplicates and cross-post the question after several days if no response has been received. And also please mention on both ends the post is a cross-post with a link to the other post.

1 Like

Sorry for this faux pas ! I deleted the other post.

It’s good that you thought to post these but try to put yourself in the shoes of a person that wants to help you. We are more interested in whether you changed anything in these configs after installation and if so, what changed. It’s a lot more effort to scan and compare.

Grav is bundled with suggested configurations for different web servers. Did you use the nginx one? It does look to me like the webserver is not correctly configured.

Sorry : I followed this installation guide : DigitalOcean | Grav Documentation

Only thing I changed is this fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; for this fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;to reflect my php version.

Fixed it. If someone experiences the same issue, here’s how I fixed it.

I added grav as a run user in the nginx.conf file located in /etc/nginx

user www-data grav;
3 Likes