Posted on Leave a comment

The Ultimate Guide/Troubleshooting To Install OsTicket On Nginx

OsTicket is an awesome ticketing system. It’s better than Hesk in my opinion. However, the sad thing about this ticketing software is it doesn’t support nginx server officially. However, if you are running Nginx, you can make it work.

Nginx configuration for OsTicket

server_name server_name;
root /path-to-your-root/;
include         mime.types;
default_type    application/octet-stream;
sendfile        on;
charset         utf- ;
gzip            on;
gzip_types      text/plain application/xml text/javascript;
gzip_min_length  ;

index index.php index.html index.htm;

set $path_info "";

# Deny access to all files in the include directory
location ~ ^/include {
deny all;
return  ;
}

# Deny access to apache .ht* files (nginx doesn't use these)
location ~ /\.ht {
deny all;
}


# Requests to /api/* need their PATH_INFO set, this does that
if ($request_uri ~ "^/api(/[^\?]+)") {
set $path_info $ ;
}

# /api/*.* should be handled by /api/http.php if the requested file does not exist
location ~ ^/api/(tickets|tasks)(.*)$ {
try_files $uri $uri/ /api/http.php;
}

# /scp/ajax.php needs PATH_INFO too, possibly more files need it hence the .*\.php
if ($request_uri ~ "^/scp/.*\.php(/[^\?]+)") {
set $path_info $ ;
}


# Make sure requests to /scp/ajax.php/some/path get handled by ajax.php
location ~ ^/scp/ajax.php/(.*)$ {
try_files $uri $uri/ /scp/ajax.php;
}

# Set index.php as our directoryindex
location / {
index index.php;
}

# Send php files off to the PHP-FPM listing on localhost: 
location ~ \.php$ {
try_files $uri = ;
fastcgi_pass    php;
fastcgi_index   index.php;
fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
fastcgi_param   PATH_INFO               $path_info;
include fastcgi_params;
}

# Make sure requests to /ajax.php/some/path get handled by ajax.php
location ~ ^/ajax.php/(.*)$ {
try_files $uri $uri/ /ajax.php;
}

How to fix file upload undefined 400 in OSTicket

Kudos to this original post: https://github.com/osTicket/osTicket-1.7/issues/538#issuecomment-16049117

If you/your users have problem uploading files when opening a ticket like this:

Then, open the file include/class.osticket.php and find the function get_path_info. Replace its definition with the block above.

    function get_path_info() {
        if(isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO']))
            return $_SERVER['PATH_INFO'];

        if(isset($_SERVER['ORIG_PATH_INFO']) && !empty($_SERVER['ORIG_PATH_INFO']))
            return $_SERVER['ORIG_PATH_INFO'];

        $request_uri = preg_replace('@\?.*$@', '', $_SERVER['REQUEST_URI']);

        if (strpos($request_uri, $_SERVER['SCRIPT_NAME']) !== false) {
            $guessed_pathinfo = preg_replace('#^'.preg_quote($_SERVER['SCRIPT_NAME']).'#', '', $request_uri);
        } else {
            $guessed_pathinfo = preg_replace('#^'.preg_quote(preg_replace('@/([^/]+)$@', '', $_SERVER['SCRIPT_NAME'])).'#', '', $request_uri);
        }
        if (!empty($guessed_pathinfo))
            return $guessed_pathinfo;

        return null;
    }

Save the file and you can now upload the attachment when opening a ticket.

Leave a Reply

Your email address will not be published. Required fields are marked *