Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BookStack installed in subfolder (nginx) #1882

Closed
MrksHfmn opened this issue Feb 9, 2020 · 6 comments
Closed

BookStack installed in subfolder (nginx) #1882

MrksHfmn opened this issue Feb 9, 2020 · 6 comments

Comments

@MrksHfmn
Copy link

MrksHfmn commented 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;
    }
}
@ssddanbrown
Copy link
Member

@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.

@FastHogi
Copy link

FastHogi commented 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
Copy link

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" />

@ssddanbrown
Copy link
Member

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.

@FastHogi
Copy link

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.

@wxrl
Copy link

wxrl commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants