Skip to content

Server static resources directly via webserver #12290

Closed

Description

@MrSorcus

Steps to reproduce

  1. Install Nextcloud.
  2. Create nginx config with location for static files
location ~ \.(css|js|svg|woff2?|ico|png)$ {
  try_files $uri =404;
}

Expected behaviour

All static resources (as css, js, woff, woff2, svg, etc.) must be separated from PHP backend.
Because current solution very slow. (VPS 1 CPU, 2GB RAM, SSD Drive)

Actual behaviour

Most resources can't be returned as static files with Nginx.
Directive try_files $uri =404; always return 404 for most of files.

Server configuration

Operating system: Archlinux latest

Web server: Nginx 1.15.5

Database: PostgreSQL 10.5

PHP version: 7.2.11

Nextcloud version: 14.0.3

Updated from an older Nextcloud/ownCloud or fresh install: Fresh install

Activity

  1. nextcloud-bot commented on Nov 5, 2018

    @nextcloud-bot
    Member

    GitMate.io thinks possibly related issues are #2045 (Cronjob separate schedules), #10077 (Fix lazy search backend), #1666 (Download of files from backend not starting), #10203 (UpdateCalendarResourcesRoomsBackgroundJob fails if no backend available), and #433 (Remove static util from theming app).

  2. MorrisJobke commented on Nov 5, 2018

    @MorrisJobke
    Member
  3. MorrisJobke commented on Nov 5, 2018

    @MorrisJobke
    Member
  4. added
    0. Needs triage
    and removed on Nov 5, 2018
  5. changed the title [-]Separate static from backend.[/-] [+]Server static resources directly via webserver[/+] on Nov 5, 2018
  6. skjnldsv commented on Nov 5, 2018

    @skjnldsv
    Member

    @rullzer 🏓
    Talked to you about this ;)

  7. Rello commented on Nov 18, 2018

    @Rello
    Contributor

    Hello,

    I don´t know if this matches my case - but I think so.
    My logs are full of 404s for all icons related to the files app

    /owncloud/svg/files/recent/000?v=1 HTTP/2.0" 404
    /owncloud/svg/files/public/000?v=1 HTTP/2.0" 404
    
    

    Core files on the other hand work - which makes NC look not too good

    /owncloud/svg/core/actions/star-dark/000?v=2 HTTP/2.0" 200
    /owncloud/svg/core/places/contacts/fff?v=1 HTTP/2.0" 200
    

    any idea how to fix it?
    screen shot 2018-11-18 at 20 50 33

  8. skjnldsv commented on Nov 18, 2018

    @skjnldsv
    Member

    @Rello Hey!
    Those urls should be forwarded through index.php. Is there anything that could prevent that in your settings?

  9. Rello commented on Nov 18, 2018

    @Rello
    Contributor

    thats what I am trying to figure out but I have now idea where to look.
    checked nginx config and logs. but have no idea...

  10. skjnldsv commented on Nov 19, 2018

    @skjnldsv
    Member

    @Rello can you post your settings! :)

  11. Rello commented on Nov 20, 2018

    @Rello
    Contributor

    Hello,

    nginx sites-available/default has exactly the same as this config (just ssl and nextcloud->owncloud replaced)
    https://docs.nextcloud.com/server/14/admin_manual/installation/nginx.html#nextcloud-in-a-subdir-of-nginx

    config.php is

    $CONFIG = array (
      'passwordsalt' => 'xx',
      'datadirectory' => '/var/owncloud',
      'dbtype' => 'mysql',
      'version' => '14.0.3.0',
      'dbname' => 'owncloud',
      'dbhost' => 'localhost',
      'dbtableprefix' => 'oc_',
      'dbuser' => 'xx',
      'dbpassword' => 'ownxxcloud',
      'installed' => true,
      'loglevel' => 1,
      'logdateformat' => 'F d, Y H:i:s',
      'log_query' => false,
      'cron_log' => false,
      'maintenance' => false,
      'forcessl' => true,
      'theme' => '',
      'default_language' => 'de',
      'knowledgebaseenabled' => false,
      'check_for_working_htaccess' => false,
      'check_for_working_webdav' => false,
      'check_for_working_wellknown_setup' => false,
      'updatechecker' => true,
      'has_internet_connection' => true,
      'appcodechecker' => false,
      'appstoreenabled' => true,
      'apps_paths' => 
      array (
        0 => 
        array (
          'path' => '/var/www/owncloud/apps',
          'url' => '/apps',
          'writable' => true,
        ),
      ),
      'trashbin_retention_obligation' => 'auto, 7',
      'filesystem_check_changes' => 1,
      'enable_avatars' => true,
      'enable_previews' => true,
      'overwritewebroot' => '/owncloud',
      'overwrite.cli.url' => 'https://xx/owncloud',
      'trusted_domains' => 
      array (
        0 => 'xx',
      ),
      'secret' => 'xx',
      'memcache.local' => '\\OC\\Memcache\\APCu',
      'appstore.experimental.enabled' => true,
      'htaccess.RewriteBase' => '/owncloud',
      'updater.release.channel' => 'stable',
      'updater.secret' => 'xx',
      'instanceid' => 'oc25od3w4bzf',
    );
    
  12. Rello commented on Nov 20, 2018

    @Rello
    Contributor

    ok,
    after testing the config.php against an empty clean NC install, the issue comes from

    'apps_paths' => 
    array (
        0 => 
        array (
          'path' => '/var/www/owncloud/apps',
          'url' => '/apps',
          'writable' => true,
        ),
      ),
    

    when I remove this section, its working perfectly fine. I am happy to have solved the issue - but ### WHY???

  13. 20 remaining items

  14. kyrofa commented on Dec 18, 2018

    @kyrofa
    Member

    One of the many icons missing is the "recent" icon there on the left. If I apply this diff (to 14.0.4), the icon shows up:

    --- old/apps/files/css/files.scss	2018-12-17 17:58:01.638811677 -0800
    +++ new/apps/files/css/files.scss	2018-12-17 17:58:05.810772707 -0800
    @@ -90,7 +90,7 @@
     	@include icon-color('folder', 'files', $color-black);
     }
     .nav-icon-recent {
    -	@include icon-color('recent', 'files', $color-black);
    +	background-image: url('../img/recent.svg?v=1');
     }
     .nav-icon-favorites {
     	@include icon-color('star-dark', 'actions', $color-black, 2, true);
    

    This diff essentially un-does 29ff7ef for the "recent" icon, which indicates to me that the issue has something to do with the icon-color function. Unfortunately, I don't know much about scss.

  15. kyrofa commented on Dec 18, 2018

    @kyrofa
    Member

    Ah, this is making a little more sense. Without the diff in the previous comment, the generated css for .nav-icon-recent looks like this (un-minified):

    .nav-icon-recent {
        background-image:var(--icon-recent-000);
    }
    

    Well, icons-vars.css has:

    --icon-recent-000: url('/index.php/svg/files/recent/000?v=1');
    

    Whereas favorites, the one that works, is in core:

    .nav-icon-favorites {
        background-image:var(--icon-star-dark-000);
    }
    
    --icon-star-dark-000: url('/index.php/svg/core/actions/star-dark/000?v=2');
    

    The former is a 404, while the latter works. It seems core icons work, but the app ones do not (which again brings me back to wondering about webroot).

  16. kyrofa commented on Dec 18, 2018

    @kyrofa
    Member

    Backporting 845f1b6 and 152fb08 to stable14 actually fixes this (which makes sense given that they embed icons instead of trying to find them using the webroot)... but it fixes it for every icon except tags. Looking into why tags isn't working whoops, it was cached. Backport does indeed work.

  17. kyrofa commented on Dec 18, 2018

    @kyrofa
    Member

    Hmm... no, something is weird. The tag icon is broken on a fresh install every time, requiring a cache-clearing refresh to work. If I visit, say, settings, and come back, the sharing icon is broken now, and no refresh helps. In both of these cases the icon is set to none in CSS (i.e. there are no 404 network errors, etc.).

  18. kyrofa commented on Dec 18, 2018

    @kyrofa
    Member

    Ah ha, 0b2ef7e was needed as well. I'm willing to bet d21ded6 is, too-- basically a complete backport of #12016. Unfortunately that gets me test failures that I don't completely understand. That isn't the lightest approach anyway, it's not a small change; I feel like it should be possible to make icon-color work when apps are outside the webroot.

  19. skjnldsv commented on Dec 18, 2018

    @skjnldsv
    Member

    @kyrofa if you access /index.php/svg/core/actions/star-dark/000?v=2 directly, what do you get?

  20. kyrofa commented on Dec 18, 2018

    @kyrofa
    Member

    @skjnldsv it works fine, but /index.php/svg/files/recent/000?v=1 is a 404.

  21. juliusknorr commented on Apr 16, 2019

    @juliusknorr
    Member

    Was fixed with #13224

  22. MrSorcus commented on Jan 30, 2020

    @MrSorcus
    Author

    Why issue closed?
    With latest version many static files can't be reached without PHP.

  23. kesselb commented on Jan 30, 2020

    @kesselb
    Contributor

    Why issue closed?

    I guess your issue got hijacked ;)

    With latest version many static files can't be reached without PHP.

    For some "static" resources it's required to serve them dynamically. Most of the theming related features. If you notice any other file with static content only provided through php please create a new report. Please refrain from creating a meta issue like "everything should be served static" and also keep note that your "files" always served dynamically.

  24. MrSorcus commented on Feb 2, 2020

    @MrSorcus
    Author

    Why issue closed?

    I guess your issue got hijacked ;)

    With latest version many static files can't be reached without PHP.

    For some "static" resources it's required to serve them dynamically. Most of the theming related features. If you notice any other file with static content only provided through php please create a new report. Please refrain from creating a meta issue like "everything should be served static" and also keep note that your "files" always served dynamically.

    Are you kidding me, right?
    Let me show you some links.
    https://gist.github.com/MrSorcus/4bdddac9c38b74d9b190335a467148ba - this is how Nextcloud return JS file.
    https://gist.github.com/MrSorcus/894d37b038c6b2dc8f66fbc8226e3edb - and this how Nginx return JS file.
    WTF? 9 req/s VS 400 req/s... Are you serious?
    PHP for static files is a BAD idea. Very bad.
    And every request to static file triggered database...
    Really? This is weird shit.
    Add command to occ to generate some dynamic resources into static, but don't do that at runtime.

    cc @juliushaertl @skjnldsv @MorrisJobke

  25. kesselb commented on Feb 2, 2020

    @kesselb
    Contributor

    I find your language very aggressive. If you expect an answer from me (because you quote me) try to rephrase your comment in a less aggressive way. Also take a look at https://nextcloud.com/contribute/code-of-conduct/

  26. MrSorcus commented on Feb 2, 2020

    @MrSorcus
    Author

    I find your language very aggressive. If you expect an answer from me (because you quote me) try to rephrase your comment in a less aggressive way. Also take a look at https://nextcloud.com/contribute/code-of-conduct/

    Yeah, you right. Sorry about this.
    https://gist.github.com/MrSorcus/4bdddac9c38b74d9b190335a467148ba - this is how Nextcloud return JS file.
    https://gist.github.com/MrSorcus/894d37b038c6b2dc8f66fbc8226e3edb - and this how Nginx return JS file.
    PHP here is very slow. About 40 times slow then Nginx.
    That's not good. And each request triggered database.
    All dynamic data, specific to user, should be returned via API.
    Or something similar.
    select2-toggleselect.js and mimetype.js is just a scripts.
    There are not needed to resolve via PHP. Just take them back to user as static.
    Other scripts / styles / images should be static too.
    Except some variants where static not possible anyway.

    cc @juliushaertl @skjnldsv @MorrisJobke

  27. kesselb commented on Feb 2, 2020

    @kesselb
    Contributor

    Other scripts / styles / images should be static too.

    Yes. It's a ongoing process. At some point in the future most of the scripts will be served statically. Feel free to submit patches to speed up the process. The current approach is to bundle most scripts with webpack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triagebugenhancementneeds info

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions