BookStackApp / BookStack

A platform to create documentation/wiki content built with PHP & Laravel
https://www.bookstackapp.com/
MIT License
14.88k stars 1.87k forks source link

APP_URL (paths to assets broken) #540

Closed nekromoff closed 6 years ago

nekromoff commented 6 years ago

Latest version.

APP_URL=http://localhost/bookstack/

CSS and other assets have broken paths. example asset path (404): http://localhost/bookstack/css/styles.css?version=v0.18.2

APP_URL=http://localhost/bookstack/public/

CSS and other assets have correct paths, but other things (such as login redirection) seem to be broken (redirection doubles path to bookstack/public/bookstack/public). example asset path (correct): http://localhost/bookstack/public/css/styles.css?version=v0.18.2

I have also checked other Laravel projects I have installed (or developed) and public folder is never required in the APP_URL path.

ssddanbrown commented 6 years ago

I have also checked other Laravel projects I have installed (or developed) and public folder is never required in the APP_URL path.

Yeah, public is not required in the APP_URL for BookStack either unless you want it to be there. Your first configuration is correct (Assuming you want http://localhost/bookstack/ as the main URL) and the CSS path for that looks correct. I'd imagine you're getting 404's due to how the webserver is configured with BookStack.

Could you paste your webserver config at all?

nekromoff commented 6 years ago

server log with public included in APP_URL:

127.0.0.1 - - [03/Oct/2017:16:25:13 +0200] "GET /bookstack/public/ HTTP/1.1" 302 1435 "http://localhost/bookstack/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/login HTTP/1.1" 200 7789 "http://localhost/bookstack/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/css/print-styles.css?version=v0.18.2 HTTP/1.1" 200 1051 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/libs/material-design-iconic-font/css/material-design-iconic-font.min.css HTTP/1.1" 200 8343 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/libs/jquery/jquery.min.js?version=2.1.4 HTTP/1.1" 200 29910 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/css/styles.css?version=v0.18.2 HTTP/1.1" 200 77742 "http://localhost/bookstack/p
ublic/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/_debugbar/assets/stylesheets?v=1500638208 HTTP/1.1" 200 111359 "http://localhost
/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/_debugbar/assets/javascript?v=1500638208 HTTP/1.1" 200 360639 "http://localhost/
bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/uploads/images/system/2017-09-Sep/scaled-200-43/1.jpg HTTP/1.1" 404 16877 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/js/common.js?version=v0.18.2 HTTP/1.1" 200 266845 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:14 +0200] "GET /bookstack/public/libs/material-design-iconic-font/fonts/Material-Design-Iconic-Font.woff2?v=2.2.0 HTTP/1.1" 200 38646 "http://localhost/bookstack/public/libs/material-design-iconic-font/css/material-design-iconic-font.min.css" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"

server log with public not included in APP_URL:

127.0.0.1 - - [03/Oct/2017:16:25:27 +0200] "GET /bookstack/public/login HTTP/1.1" 200 7393 "http://localhost/bookstack/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:28 +0200] "GET /bookstack/css/styles.css?version=v0.18.2 HTTP/1.1" 404 513 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:28 +0200] "GET /bookstack/libs/jquery/jquery.min.js?version=2.1.4 HTTP/1.1" 404 524 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:28 +0200] "GET /bookstack/libs/material-design-iconic-font/css/material-design-iconic-font.min.css HTTP/1.1" 404 571 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:28 +0200] "GET /bookstack/js/common.js?version=v0.18.2 HTTP/1.1" 404 511 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:28 +0200] "GET /bookstack/css/print-styles.css?version=v0.18.2 HTTP/1.1" 404 520 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:28 +0200] "GET /bookstack/public/_debugbar/assets/javascript?v=1500638208 HTTP/1.1" 200 360640 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:28 +0200] "GET /bookstack/public/_debugbar/assets/stylesheets?v=1500638208 HTTP/1.1" 200 111360 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
127.0.0.1 - - [03/Oct/2017:16:25:28 +0200] "GET /bookstack/public/uploads/images/system/2017-09-Sep/scaled-200-43/1.jpg HTTP/1.1" 404 16876 "http://localhost/bookstack/public/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
ssddanbrown commented 6 years ago

Those logs are what I'd expect really. Could you post your server config? Apache config or Nginx config or other...

nekromoff commented 6 years ago

.htacess in public/:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

apache2/sites-enabled/000-default.conf:

<Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>

apache2/apache2.conf:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

nothing else much that should be related.

ssddanbrown commented 6 years ago

@nekromoff Ah, Okay, From the above I'm assuming you're just putting the BookStack install within /var/www and then trying to access at http://example.com/bookstack-folder.

For BookStack that kind of setup is not recommended as it exposes loads of PHP files and has the potential to expose private configuration files easily. Ideally you want to put the BookStack folder somewhere else that's not directly accessible by apache.

The easiest method is to put BookStack on the root of your domain (eg. http://example.com) instead of putting it on a sub-path (http://example.com/docs) but it is possible to use a subpath if required:

I got this working on apache with the below config. You'll need to change /bookstack/install/path below to where you put your BookStack install, the /public part should stay. Advise below is at your own risk. Ensure you make backups.

Add this to your server (Within apache2/apache2.conf) or VirtualHost config:

Alias /docs /bookstack/install/path/public

You'll need to change /docs to the url path you want. This will change any requests starting with a path /docs to target the your BookStack install instead of the normal server DocumentRoot.

Add the following directory block (Can be in apache2/apache2.conf or apache2/sites-enabled/000-default.conf I think):

<Directory "/bookstack/install/path/public">
    AllowOverride None
    Require all granted
    <IfModule mod_rewrite.c>
        Options -MultiViews

        RewriteEngine On

        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/$ /$1 [L,R=301]

        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
</Directory>

This block handles the requests to the BookStack install folder and prevents the need to use the .htaccess file which will improve performance and security.

Let me know if any of the above makes no sense or you need further help.

nekromoff commented 6 years ago

Thanks for that explanation. The thing is I want to run Bookstack on a shared hosting, where such config changes are not easy, if not impossible at all.

Also, as I have mentioned other Laravel applications I use (or have developed) don't have these path issues, so I think this is maybe a conceptual problem with Bookstack.

nekromoff commented 6 years ago

Indeed, it is conceptual difference:

another Laravel app (default asset functions):

        <!-- Styles -->
        <link href="{{ asset('css/datatables.min.css') }}" rel="stylesheet">
        <link href="{{ asset('css/buttons.dataTables.min.css') }}" rel="stylesheet">
        <link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet">
        <link href="{{ asset('css/main.css') }}" rel="stylesheet">

        <!-- Latest compiled and minified JavaScript -->
        <script src="{{ asset('js/jquery-3.1.1.slim.min.js') }}"></script>
        <script src="{{ asset('js/bootstrap.min.js') }}"></script>
        <script src="{{ asset('js/datatables.min.js') }}"></script>
        <script src="{{ asset('js/dataTables.buttons.min.js') }}"></script>
        <script src="{{ asset('js/buttons.html5.min.js') }}"></script>

Bookstack (custom asset functions):

    <!-- Styles and Fonts -->
    <link rel="stylesheet" href="{{ versioned_asset('css/styles.css') }}">
    <link rel="stylesheet" media="print" href="{{ versioned_asset('css/print-styles.css') }}">
    <link rel="stylesheet" href="{{ baseUrl("/libs/material-design-iconic-font/css/material-design-iconic-font.min.css") }}">

    <!-- Scripts -->
    <script src="{{ baseUrl("/libs/jquery/jquery.min.js?version=2.1.4") }}"></script>

use of {{ asset('') }} is recommended: https://laravel.com/docs/5.5/helpers#method-asset

sgvandijk commented 6 years ago

@ssddanbrown thanks for your suggestions, I am still having issues with my setup though. This is the full config at /etc/apache2/sites-enabled/bookstack.conf(there are no other files in sites-enabled):

<VirtualHost *:80>
  ServerName bookstack.dev
  DocumentRoot /var/www/bookstack

  <Directory "/var/www/bookstack/">
    Options FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
  </Directory>

  Alias /bookstack /var/www/bookstack/public

  <Directory "/var/www/bookstack/public/">
    AllowOverride None
    Require all granted
    <IfModule mod_rewrite.c>               

      RewriteEngine On                   

      # Redirect Trailing Slashes If Not A Folder...                             
      RewriteCond %{REQUEST_FILENAME} !-d                                        
      RewriteRule ^(.*)/$ /$1 [L,R=301]  

      # Handle Front Controller...       
      RewriteCond %{REQUEST_FILENAME} !-d                                        
      RewriteCond %{REQUEST_FILENAME} !-f                                        
      RewriteRule ^ index.php [L]        
    </IfModule>
  </Directory>
</VirtualHost>

I am running in docker, mostly based on https://github.com/solidnerd/docker-bookstack, except for the config above and that the .htaccess file is removed. It's running behind HAProxy that directs any /bookstack requests to the docker container. APP_URL is set to http://myhost/bookstack

When I browse to http://myhost/bookstack, it redirects to http://myhost/bookstack/login, but that gives a Bookstack styled 'page not found page' (with css assets etc loaded correctly). http://myhost/bookstack/index.php/login does load the login page. It seems the rewrite rules are not the correct one, also because if I add a trailing slash, e.g. http://myhost/bookstack/login/, it gets redirected to http://myhost/login. I have tried several combinations, but my apache knowledge is limited and I haven't been able to get it to work properly.

ssddanbrown commented 6 years ago

Thank you for opening this issue. As part of an issue clean-up we're closing off older support issues that may be outdated or irrelevant so therefore I am closing this issue.

If the issue remains and it is one you are still seeking to actively solve please ensure it is still not apparent on the latest version of BookStack then open up a new issue referencing this one.

Sorry if we were not able to solve your original request.