Skip to content

Working nginx config for a subdirectory install #2747

@EugeneDae

Description

@EugeneDae

According to #1005 and #1610 FreeScout supports subdirectory installation (e.g. https://example.com/freescout/ instead of https://freescout.example.com), however if I use the nginx config from the Installation Guide I cannot get nginx to serve static files without breaking FreeScout's routing.

Here's my current nginx config:

server {
    ...
    
    root /var/www/freescout/public;
    index index.php index.html;

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

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

...and here's what it gets me:
01
02

This is what I've tried:

server {
    ...
    root /var/www/freescout/public;
    index index.php index.html;

    location /freescout {
        alias /var/www/freescout/public;
        try_files $uri $uri/ /index.php?$query_string;
    }

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

It fixes static files but breaks the routing:
03
04

Interestingly, in this case (if I clear the cookies) /freescout/login/ works correctly:
05

(The APP_URL parameter in the .env file is set correctly).

I'm thinking I need a rewrite somewhere, but I wonder what is the recommended way of solving this? Any tips would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions