Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Installation & Hosting

Grav can't load CSS and JS on webserver

Solved by DouxDoux View solution

Started by DouxDoux 3 years ago · 5 replies · 392 views
3 years ago

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 :
image|690x245

Same thing if I look at the source :
image|690x140

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 :

TXT
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 :

TXT
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
}
last edited 12/17/23 by DouxDoux
3 years ago

@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
3 years ago

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

3 years ago

@douxdoux-1312:
if it can help, here’s my grav file in /etc/nginx/sites-available :

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.

3 years ago Solution

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

TXT
user www-data grav;
👍 3

Suggested topics

Topic Participants Replies Views Activity
Installation & Hosting · by antoinep, 18 hours ago
6 63 6 minutes ago
Installation & Hosting · by Jürgen Dietrich, 7 months ago
0 65 7 months ago
Installation & Hosting · by rappluk, 8 months ago
0 64 8 months ago
Installation & Hosting · by N, 12 months ago
3 76 12 months ago
Installation & Hosting · by Youle, 1 year ago
1 63 1 year ago