Nginx and Panel configuration problem

I’ve been having some trouble with a Kirby + Nginx setup. The project runs smoothly and all the rewrites work well it’s just that the panel is not working. The login screen seems to work but once I try to login it just stays there. No error message being thrown anywhere.

The basic configuration stuff was taken from: https://gist.github.com/bastianallgeier/c2e1f1e519f5f2943ec4#gistcomment-1795907

Any Nginx user that can help? This is the server configuration file:

server {
          #error_log /var/log/nginx/vhost-error_log warn;
          listen X.X.X.X:80;
          listen [::]:80;
          listen 443;

          ssl_certificate /home/user/ssl/certs/ssl-bundle-sha2.crt;
          ssl_certificate_key /home/user/ssl/keys/1440180419.granvia.mx.key;

          server_name trendwalker.granvia.mx www.trendwalker.granvia.mx;

          access_log /usr/local/apache/domlogs/trendwalker.granvia.mx-bytes_log bytes_log;
          access_log /usr/local/apache/domlogs/trendwalker.granvia.mx combined;
          set $root_path '/home/granviam/public_html/sub_trendwalker/test';
          root $root_path;

          location / {
                index index.php index.html index.htm;
                try_files $uri $uri/ /index.php?q=$uri&$args;
          }
          charset utf-8;

          # panel links
          location /panel {
                index index.php index.html index.htm;
                try_files $uri $uri/ /panel/index.php?$uri&$args;
          }


          location ~* ^/(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
                  root $root_path;
                  expires max;
          }
location ~* ^/(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
                  root $root_path;
                  expires max;
          }

          location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_read_timeout 300;

                #proxy_pass http://X.X.X.X:80;
                include /etc/nginx/fastcgi_params;
                #include proxy.inc;
                include microcache.inc;
          }

          location ~ /\.ht {
          deny all;
          }

        ## Block download agents ##
        if ($http_user_agent ~* LWP::Simple|BBBike|wget) {
                return 403;
        }

        ## Block some robots ##
        if ($http_user_agent ~* msnbot|scrapbot) {
                return 403;
        }

        ## Deny certain Referers ###
        if ( $http_referer ~* (babes|jewelry|organic|poker|porn|viagra))
        {
                # return 404;
                return 403;
        }

}

And here’s the last two errors from the nginx_error.log

PHP message: PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0" while reading upstream, client: XXX.XXX.XXX.XXX, server: trendwalker.granvia.mx, request: "GET /panel/login HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "trendwalker.granvia.mx"
2016/08/10 12:48:24 [error] 24622#24622: *26068 FastCGI sent in stderr: "PHP message: PHP Warning:  session_start(): open(/var/lib/php/session/sess_is8fiku13gjs48dinonhtijhl4, O_RDWR) failed: Permission denied (13) in /home/granviam/public_html/sub_trendwalker/test/kirby/toolkit/lib/s.php on line 54
PHP message: PHP Warning:  Unknown: open(/var/lib/php/session/sess_is8fiku13gjs48dinonhtijhl4, O_RDWR) failed: Permission denied (13) in Unknown on line 0
PHP message: PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0" while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: trendwalker.granvia.mx, request: "POST /panel/login HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "trendwalker.granvia.mx", referrer: "https://trendwalker.granvia.mx/panel/login"
2016/08/10 12:48:24 [error] 24622#24622: *26068 FastCGI sent in stderr: "PHP message: PHP Warning:  session_start(): open(/var/lib/php/session/sess_is8fiku13gjs48dinonhtijhl4, O_RDWR) failed: Permission denied (13) in /home/granviam/public_html/sub_trendwalker/test/kirby/toolkit/lib/s.php on line 54" while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: trendwalker.granvia.mx, request: "GET /panel/login HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "trendwalker.granvia.mx", referrer: "https://trendwalker.granvia.mx/panel/login"
2016/08/10 12:48:24 [error] 24622#24622: *26068 FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: open(/var/lib/php/session/sess_is8fiku13gjs48dinonhtijhl4, O_RDWR) failed: Permission denied (13) in Unknown on line 0
PHP message: PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0" while reading upstream, client: XXX.XXX.XXX.XXX, server: trendwalker.granvia.mx, request: "GET /panel/login HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "trendwalker.granvia.mx", referrer: "https://trendwalker.granvia.mx/panel/login"

My configuration is bit different and works:

location ~ /panel { # with the ~
    index index.php;
    try_files $uri $uri/ /panel/index.php?$uri&$args;
}

Does that work for you?

Actually looking at the error message it looks like your problem is not Nginx. I had a similar issue when trying PHP 7 beta back in December. Since the stable release came out I have had no issue.

The solution will depend on your OS and PHP version. Googling the error message help me at the time.

1 Like

Thanks for the suggestion!

The system admin mentioned something about rebuilding PHP tomorrow. In the meantime I’ll try to learn more about those error warnings.

So, the system administrator solved it with the help of this thread:

It seems Kirby was looking for the PHP session in a different route than configured.

Anyone can help? Where i should put “session_save_path(sys_get_temp_dir());”??? Thanks in advance!

A post was merged into an existing topic: Nginx and kirby into subdir