Cockpit: nginx config?

Created on 3 Jan 2014  路  19Comments  路  Source: agentejo/cockpit

Wondering if anyone has a working nginx config for cockpit... I'm having a little trouble. I do actually get the install page back with a success message, but then I wind up at a 404 upon attempt to reach login...

e.g. /manage/index.php/auth/login

(cockpit itself lives in the /manage subfolder within the otherwise static site)

docs

Most helpful comment

Just in case anyone has issues still ( I did today ), the following nginx config worked for me:

server {
    listen 80;
    server_name _ myCockpit.com;
    root /var/www/html/cockpit-master;
    index index.php;

    location / {
      try_files $uri $uri/ /index.php;
    }

    access_log  /var/log/nginx/cockpit.access.log;
    error_log   /var/log/nginx/cockpit.error.log;

    # Deny direct access to .sqlite
    location ~ .sqlite$ {
        deny all;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param COCKPIT_URL_REWRITE On;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    location ~ /\.ht {
        deny all;
    }
}

All 19 comments

It seems that $_SERVER['PATH_INFO'] is missing....maybe this site might help: http://wiki.nginx.org/PHPFcgiExample

Hi, same issue but i have this line, any idea ?

Same here. Install worked, but I can't get past that.

does this information help?

http://stackoverflow.com/questions/15316742/nginx-configuration-php-frameworks-with-pathinfo-404

I'll try to setup a nginx env in the next days to replicate the issue.

Unfortunately I didn't have any luck with the suggestions in that Stack Overflow thread. But I'm anxious to see what you find!

I updated the cockpit code and would appreciate it if you could test it. Please download the latest master:

https://github.com/aheinze/cockpit/archive/master.zip

and add the following rule to your server config:

location /cockpit {
     try_files $uri $uri/ /cockpit/index.php;
}

change cockpit to the folder name you extracted the cockpit zip.

Thanks for testing and feedback!

Hi, no change for me :(

could you please provide you server config?

Same here.
I get redirected to "install" an then nothing :(

http://example.com/cockpit/install works fine and i get redirected to http://example.coom/cockpit which results in an 404. Adding index.php doesn't help, but adding a trailing slash works.

http://example.com/cockpit -- doesn't work
http://example.com/cockpit/index.php -- doesn't work
http://example.com/cockpit/index.php/ -- works

Same issue as above,

server {
    listen cockpit:80;
    server_name cockpit;
    access_log /var/log/nginx/cockpit.access.log;
    error_log /var/log/nginx/cockpit.error.log;
    root /srv/cockpit;
    index index.html index.htm index.php;
    location  / {        
        try_files $uri $uri/ /index.php;
    }
    location ~ .sqlite$ {        
        deny all;
    }

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;

        fastcgi_index index.php;
        include fcgi.conf;
        fastcgi_pass unix:/var/run/php-fcgi-cockpit-php-fcgi-2.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    }

}

I've the same problem, partially solved with this :

  1. verify that all "fastcgi_param" are set
    PATH_INFO, REQUEST_URI, PHP_SELF in priority (used in the index.php). For others params see http://wiki.nginx.org/PHPFcgiExample.
  2. Fix fastcgi path_info
location ~ [^/]\.php(/|$) {
    ...
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    ...
}

Now, if i get index.php/auth/login, it works !!!

The last problem i have : if i go to the index.php before being logged, cockpit does not redirect to the login page.

Just for everyone's info...

PATH_INFO has always been broken on nginx, and it doesn't look like it will be fixed anytime soon, as apparently it is an outdated concept :(

Is there any way that cockpit can be updated to do without this server var?

@designermonkey PATH_INFO dependency is now removed in the current release

Thanks :)

I had the same issue with the following config:

server {
    listen 80;
    server_name cockpit.dev;
    root /usr/share/nginx/html/cockpit;
    index index.php index.html index.htm;

    error_log /var/log/nginx/cockpit_error.log.txt;
    access_log /var/log/nginx/cockpit_access.log.txt;

    # Add additional types
    include mime.types;

    location / {
        index index.php index.html index.htm;
    }

    # Change "cockpit" to the folder name containing cockpit files.
    location /cockpit {
        try_files $uri $uri/ /cockpit/index.php;
        index index.php index.html index.htm;
    }

    location ~ \.php(/|\?|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param COCKPIT_URL_REWRITE On;
        include fastcgi_params;
    }

    location ~ .sqlite$ {
        deny all;
    }
}

And the file structure is

/www(root)/cockpit/*

error log is

 "/usr/share/nginx/html/cockpit/auth/login" failed (2: No such file or directory), client: 121.121.121.1, server: cockpit.dev, request: "GET /auth/login HTTP/1.1", host: "cockpit.dev"

Just in case anyone has issues still ( I did today ), the following nginx config worked for me:

server {
    listen 80;
    server_name _ myCockpit.com;
    root /var/www/html/cockpit-master;
    index index.php;

    location / {
      try_files $uri $uri/ /index.php;
    }

    access_log  /var/log/nginx/cockpit.access.log;
    error_log   /var/log/nginx/cockpit.error.log;

    # Deny direct access to .sqlite
    location ~ .sqlite$ {
        deny all;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param COCKPIT_URL_REWRITE On;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    location ~ /\.ht {
        deny all;
    }
}

Thank you, lhardie. You're a life saver! I was trying it for the whole day and was always running into the same problem.
Cockpit's documentation strongly needs more detailed installation instructions in this regard.

It seems that the crucial part is the following line:
try_files $uri $uri/ /index.php;

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erkand-imeri picture erkand-imeri  路  6Comments

gryphonmyers picture gryphonmyers  路  6Comments

tsimenis picture tsimenis  路  5Comments

HausOfAlejandro picture HausOfAlejandro  路  4Comments

pauloamgomes picture pauloamgomes  路  5Comments