BookStack installed in subfolder (nginx) #1526

Closed
opened 2026-02-05 01:08:45 +03:00 by OVERLORD · 6 comments
Owner

Originally created by @MrksHfmn on GitHub (Feb 9, 2020).

is it possible to run bookstack under a subfolder? I would like to call bookstack like this: https://sub.domain.org/bookstack

i use nginx, that's my current approach:

location ^~ /bookstack/public {
    root /mnt/storage/services;
    index index.php;
    try_files $uri $uri/ /bookstack/public/index.php;

location ~ \.php$ {
        try_files $uri =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass   127.0.0.1:9000;
    }
}
Originally created by @MrksHfmn on GitHub (Feb 9, 2020). is it possible to run bookstack under a subfolder? I would like to call bookstack like this: https://sub.domain.org/bookstack i use nginx, that's my current approach: ``` location ^~ /bookstack/public { root /mnt/storage/services; index index.php; try_files $uri $uri/ /bookstack/public/index.php; location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } } ```
OVERLORD added the 🐕 Support Question labels 2026-02-05 01:08:45 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Feb 10, 2020):

@MrksHfmn Yeah, It's totally possible. I've done it before by proxying the sub-path to another local URL or docker container URL.

I've just tried to do it without proxies and secceeded by following this guide (TL;DR section).

You'll need to set the APP_URL parameter in your .env file like so:

APP_URL=http://sub.domain.org/bookstack

Just make sure none of your BookStack files & folders are within/below another web-server directory on the file-system; None of the BookStack files outside of the /public directory should be exposed for web access.

@ssddanbrown commented on GitHub (Feb 10, 2020): @MrksHfmn Yeah, It's totally possible. I've done it before by proxying the sub-path to another local URL or docker container URL. I've just tried to do it without proxies and secceeded by [following this guide](https://serversforhackers.com/c/nginx-php-in-subdirectory) (**TL;DR section**). You'll need to set the `APP_URL` parameter in your `.env` file like so: ```bash APP_URL=http://sub.domain.org/bookstack ``` Just make sure none of your BookStack files & folders are within/below another web-server directory on the file-system; None of the BookStack files outside of the `/public` directory should be exposed for web access.
Author
Owner

@FastHogi commented on GitHub (Jan 24, 2021):

@ssddanbrown Thank you for this tipp. I followed your mentioned guide (https://serversforhackers.com/c/nginx-php-in-subdirectory) and added the following nginx sections to use BookStack in a subfolder:

location /bookstack {
alias /var/www/BookStack/public;

              access_log  /var/log/nginx/bookstack_access.log;
              error_log  /var/log/nginx/bookstack_error.log;

              client_max_body_size 1G;
              fastcgi_buffers 64 4K;

              index index.php;
              try_files $uri $uri/ @bookstack;

              location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README) {
                      deny all;
              }

              location ~ \.php$ {
                      include snippets/fastcgi-php.conf;
                      fastcgi_split_path_info ^(.+\.php)(/.+)$;
                      include fastcgi_params;
                      fastcgi_param SCRIPT_FILENAME $request_filename;
                      fastcgi_param PATH_INFO $fastcgi_path_info;
                      fastcgi_pass unix:/run/php/php7.4-fpm.sock;
              }

              location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
                      expires 30d;
                      access_log off;
              }
      }

      location @bookstack {
              rewrite ^/bookstack/(.*)$ /bookstack/index.php?/$1 last;
      }

Everything is working except the first request after a login. I'm always redirected to /bookstack/bookstack right after I click on the login button, which results in a page not found message in bookstack. After clicking on a created book ot shelv link, everything is working as excepted and no "page not found messages" appears. so it's only happening right after the login.

I'm wondering if this is bug in the login php method or if there's still a tiny little problem in the nginx redirect rule. Another problem is the switch from bright to dark mode or the other way round. It's not working if you're using BookStack in a subfolder, because then I'm routed from the /subfolder back to /.

Any help is appreciated.

@FastHogi commented on GitHub (Jan 24, 2021): @ssddanbrown Thank you for this tipp. I followed your mentioned guide (https://serversforhackers.com/c/nginx-php-in-subdirectory) and added the following nginx sections to use BookStack in a subfolder: location /bookstack { alias /var/www/BookStack/public; access_log /var/log/nginx/bookstack_access.log; error_log /var/log/nginx/bookstack_error.log; client_max_body_size 1G; fastcgi_buffers 64 4K; index index.php; try_files $uri $uri/ @bookstack; location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README) { deny all; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_pass unix:/run/php/php7.4-fpm.sock; } location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ { expires 30d; access_log off; } } location @bookstack { rewrite ^/bookstack/(.*)$ /bookstack/index.php?/$1 last; } Everything is working except the first request after a login. I'm always redirected to /bookstack/bookstack right after I click on the login button, which results in a page not found message in bookstack. After clicking on a created book ot shelv link, everything is working as excepted and no "page not found messages" appears. so it's only happening right after the login. I'm wondering if this is bug in the login php method or if there's still a tiny little problem in the nginx redirect rule. Another problem is the switch from bright to dark mode or the other way round. It's not working if you're using BookStack in a subfolder, because then I'm routed from the /subfolder back to /. Any help is appreciated.
Author
Owner

@FastHogi commented on GitHub (Jan 25, 2021):

I discovered another (tiny) problem when you are moving BookStack into a subfolder. As far as I understand the favicon isn't delivered in the html head section in BookStack. That means the browser is always requesting for a possible favicon image from the root folder ("/favicon.ico") and that's not the correct one if you are moving BookStack into a subfolder if you have a favicon unter "/" from another web app.

This could be solved if BookStack would deliver the favicon image with the base url from .env like so:

<link rel="shortcut icon" type="image/x-icon" href="http://www.example.com/favicon.ico">

or in the subfolder case

<link rel="shortcut icon" type="image/x-icon" href="http://www.example.com/subfoldername/favicon.ico">.

There is no favicon for apple devices and no icon is shown under Safari, which could also be delivered in the head section:

<link rel="apple-touch-icon" sizes="180x180" href="public/img/apple-touch-icon.png" />

@FastHogi commented on GitHub (Jan 25, 2021): I discovered another (tiny) problem when you are moving BookStack into a subfolder. As far as I understand the favicon isn't delivered in the html head section in BookStack. That means the browser is always requesting for a possible favicon image from the root folder ("/favicon.ico") and that's not the correct one if you are moving BookStack into a subfolder if you have a favicon unter "/" from another web app. This could be solved if BookStack would deliver the favicon image with the base url from .env like so: `<link rel="shortcut icon" type="image/x-icon" href="http://www.example.com/favicon.ico">` or in the subfolder case `<link rel="shortcut icon" type="image/x-icon" href="http://www.example.com/subfoldername/favicon.ico">`. There is no favicon for apple devices and no icon is shown under Safari, which could also be delivered in the head section: `<link rel="apple-touch-icon" sizes="180x180" href="public/img/apple-touch-icon.png" />`
Author
Owner

@ssddanbrown commented on GitHub (Jan 26, 2021):

Hi @FastHogi,
What you describe regarding the login redirect sounds very much like the issue in #2058, which I've assigned to be revisited for the next release.

In regards to the favicon, That's the behaviour I'd expect and prefer to remain. If someone is using bookstack on a sub-path of an existing site, I'd prefer to allow the favicon be used from that existing site. If needed, this can always be updated in BookStack, using the HTML examples you've shown, within the "Custom HTML Head Content" setting.

Since there's been no response from the original author of this issue I'm going to close this off but if you have any further problems, feel free to open a new issue.

@ssddanbrown commented on GitHub (Jan 26, 2021): Hi @FastHogi, What you describe regarding the login redirect sounds very much like the issue in #2058, which I've assigned to be revisited for the next release. In regards to the favicon, That's the behaviour I'd expect and prefer to remain. If someone is using bookstack on a sub-path of an existing site, I'd prefer to allow the favicon be used from that existing site. If needed, this can always be updated in BookStack, using the HTML examples you've shown, within the "Custom HTML Head Content" setting. Since there's been no response from the original author of this issue I'm going to close this off but if you have any further problems, feel free to open a new issue.
Author
Owner

@FastHogi commented on GitHub (Jan 26, 2021):

Hi @ssddanbrown,
thank you for your feedback and the hint regarding the "Customer HTML Head Content" setting. I added

<link rel="shortcut icon" type="image/x-icon" href="/bookstack/favicon-custom.ico"/>
<link rel="apple-touch-icon" sizes="180x180" href="/bookstack/favicon-apple.png"/>

and yep, that works. Both favicons now appear perfectly on all devices from my subfolder.

@FastHogi commented on GitHub (Jan 26, 2021): Hi @ssddanbrown, thank you for your feedback and the hint regarding the "Customer HTML Head Content" setting. I added ``` <link rel="shortcut icon" type="image/x-icon" href="/bookstack/favicon-custom.ico"/> <link rel="apple-touch-icon" sizes="180x180" href="/bookstack/favicon-apple.png"/> ``` and yep, that works. Both favicons now appear perfectly on all devices from my subfolder.
Author
Owner

@wxrl commented on GitHub (Jun 25, 2021):

Hi @FastHogi,
What you describe regarding the login redirect sounds very much like the issue in #2058, which I've assigned to be revisited for the next release.

In regards to the favicon, That's the behaviour I'd expect and prefer to remain. If someone is using bookstack on a sub-path of an existing site, I'd prefer to allow the favicon be used from that existing site. If needed, this can always be updated in BookStack, using the HTML examples you've shown, within the "Custom HTML Head Content" setting.

Since there's been no response from the original author of this issue I'm going to close this off but if you have any further problems, feel free to open a new issue.

Had the same issue once login after putting a nginx server alias subfolder "mydomain.com/bookstack" to bookstack/public, the URL returns to mydomain.com/bookstack/bookstack with the latest bookstack version.

Any update on solving this with nginx? Thanks!

@wxrl commented on GitHub (Jun 25, 2021): > Hi @FastHogi, > What you describe regarding the login redirect sounds very much like the issue in #2058, which I've assigned to be revisited for the next release. > > In regards to the favicon, That's the behaviour I'd expect and prefer to remain. If someone is using bookstack on a sub-path of an existing site, I'd prefer to allow the favicon be used from that existing site. If needed, this can always be updated in BookStack, using the HTML examples you've shown, within the "Custom HTML Head Content" setting. > > Since there's been no response from the original author of this issue I'm going to close this off but if you have any further problems, feel free to open a new issue. Had the same issue once login after putting a nginx server alias subfolder "mydomain.com/bookstack" to bookstack/public, the URL returns to mydomain.com/bookstack/bookstack with the latest bookstack version. Any update on solving this with nginx? Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1526