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

Nginx subfolder for news/blog

Solved by Dan View solution

Started by Dan 5 years ago · 3 replies · 2046 views
5 years ago

Hey

I'm trying to run GRAV in a subfolder of my main website in a different root folder. So far I get only File not found. by visting my site under https://my.site/news/.

My nginx code for GRAV is:

TXT
# GRAV
    location ^~ /news {
        alias /srv/http/grav/;
        index index.php index.html index.htm;

        rewrite ^/news/(.*)+$ /news/index.php?$1;
        try_files $uri $uri/ /news/index.php?$query_string;

        ## Begin - PHP
        location ~ \.php$ {
           fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_index index.php;
           include fastcgi_params;
           fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        }
        ## End - PHP
    }

What am I missing here?

5 years ago

At the moment I'm just trying to install it. But I'll probably need the link later as well.
I just can't get through to the installation. Just File not found. So problem on nginx config?

Anyway, I also tried a few things from the link you have posted, but exactly the same problem.

5 years ago Solution

Ok. I found the issue. I just forgot to add my php config file include php.conf;.
Whole subfolder config is now:

TXT
# GRAV
    location ^~ /news {
        alias /srv/http/grav/;
        index index.php index.html index.htm;

        if (!-e $request_filename) { rewrite ^ /news/index.php last; }
        try_files $uri $uri/ /news/index.php?$query_string;

        ## 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)$ { return 403; }
        # deny running scripts inside user folder
        location ~* /user/.*\.(txt|md|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

        if ($request_method !~ ^(GET|HEAD|POST)$ ) {
           return 405;
        }

        location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|webp|woff2)$ {
           expires 2d;
           add_header Cache-Control "public, no-transform, max-age=31536000";
        }

        access_log /var/log/nginx/grav_access.log;
        error_log /var/log/nginx/grav-error.log;

        include php.conf;
    }

If someone need it.

last edited 11/07/21 by Dan

Suggested topics

Topic Participants Replies Views Activity
Installation & Hosting · by antoinep, 20 hours ago
7 73 2 hours ago
Installation & Hosting · by Jürgen Dietrich, 7 months ago
0 65 7 months ago
Installation & Hosting · by rappluk, 8 months ago
0 65 8 months ago
Installation & Hosting · by N, 12 months ago
3 76 12 months ago
Installation & Hosting · by Youle, 1 year ago
1 65 1 year ago