xsendfile.html 15.1 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Serving static files via web server &mdash; ownCloud Administrators Manual 7.0 documentation</title>
    
    <link rel="stylesheet" href="../_static/style.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/style.css" type="text/css" />
    <link rel="stylesheet" href="../_static/bootstrap-sphinx.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '7.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/bootstrap.js"></script>
    <link rel="top" title="ownCloud Administrators Manual 7.0 documentation" href="../index.html" />
    <link rel="up" title="Configuration" href="index.html" />
    <link rel="next" title="Maintenance" href="../maintenance/index.html" />
    <link rel="prev" title="Custom User Backend Configuration" href="custom_user_backend.html" />
<script type="text/javascript">
(function () {
  /**
   * Patch TOC list.
   *
   * Will mutate the underlying span to have a correct ul for nav.
   *
   * @param $span: Span containing nested UL's to mutate.
   * @param minLevel: Starting level for nested lists. (1: global, 2: local).
   */
  var patchToc = function ($ul, minLevel) {
    var findA;

    // Find all a "internal" tags, traversing recursively.
    findA = function ($elem, level) {
      var level = level || 0,
        $items = $elem.find("> li > a.internal, > ul, > li > ul");

      // Iterate everything in order.
      $items.each(function (index, item) {
        var $item = $(item),
          tag = item.tagName.toLowerCase(),
          pad = 15 + ((level - minLevel) * 10);

        if (tag === 'a' && level >= minLevel) {
          // Add to existing padding.
          $item.css('padding-left', pad + "px");
          console.log(level, $item, 'padding-left', pad + "px");
        } else if (tag === 'ul') {
          // Recurse.
          findA($item, level + 1);
        }
      });
    };

    console.log("HERE");
    findA($ul);
  };

  $(document).ready(function () {
    // Add styling, structure to TOC's.
    $(".dropdown-menu").each(function () {
      $(this).find("ul").each(function (index, item){
        var $item = $(item);
        $item.addClass('unstyled');
      });
      $(this).find("li").each(function () {
        $(this).parent().append(this);
      });
    });

    // Patch in level.
    patchToc($("ul.globaltoc"), 2);
    patchToc($("ul.localtoc"), 2);

    // Enable dropdown.
    $('.dropdown-toggle').dropdown();
  });
}());
</script>

  </head>
  <body>
  

<div class="container">
  <div class="content">
    <div class="page-header">
      <h1><a href="../contents.html">ownCloud Administrators Manual</a></h1>

    </div>
    
			<div class="row">
				<div class="span3">
					<div class="sidebar">
						<div class="well">
							<div class="menu-support-container">
								<ul id="menu-support" class="menu">
									<ul>
										<li><a href="../contents.html">Overview</a></li>
									</ul>
                  <ul>
<li class="toctree-l1"><a class="reference internal" href="../index.html">Introduction</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Configuration</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="configuration_apps.html">Apps Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_users.html">User Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="auth_ldap.html">User Authentication with LDAP</a></li>
<li class="toctree-l2"><a class="reference internal" href="server_to_server_managing.html">Managing Server-to-Server Sharing Access</a></li>
<li class="toctree-l2"><a class="reference internal" href="background_jobs.html">Defining Background Jobs</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_assets.html">Asset Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_3rdparty.html">Using Third Party Components</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_automation.html">Defining Automatic Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_custom_clients.html">Custom Client Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_database.html">Database Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_encryption.html">Use Server-Side Encryption</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_knowledgebase.html">Knowledge Base Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_language.html">Language Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_logging.html">Logging Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_mail.html">Mail Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_preview.html">Preview Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuration_reverseproxy.html">Reverse Proxy Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuring_big_file_upload.html">Uploading big files &gt; 512MB (as set by default)</a></li>
<li class="toctree-l2"><a class="reference internal" href="configuring_big_file_upload.html#enabling-uploading-big-files">Enabling uploading big files</a></li>
<li class="toctree-l2"><a class="reference internal" href="custom_mount_config_gui.html">Custom Mount Configuration (GUI)</a></li>
<li class="toctree-l2"><a class="reference internal" href="custom_mount_config.html">Custom Mount Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="custom_user_backend.html">Custom User Backend Configuration</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="">Serving static files via web server</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#apache2-x-sendfile">Apache2 (X-Sendfile)</a></li>
<li class="toctree-l3"><a class="reference internal" href="#lighttpd-x-sendfile2">LigHTTPd (X-Sendfile2)</a></li>
<li class="toctree-l3"><a class="reference internal" href="#nginx-x-accel-redirect">Nginx (X-Accel-Redirect)</a></li>
<li class="toctree-l3"><a class="reference internal" href="#how-to-check-if-it-s-working">How to check if it&#8217;s working?</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../maintenance/index.html">Maintenance</a></li>
<li class="toctree-l1"><a class="reference internal" href="../issues/index.html">Issues</a></li>
</ul>

								</ul>
							</div>
						</div>
					</div>
				</div>
        

				<div class="span9">
					<div class="page-content">
						
  <div class="section" id="serving-static-files-via-web-server">
<h1>Serving static files via web server<a class="headerlink" href="#serving-static-files-via-web-server" title="Permalink to this headline">¶</a></h1>
<p>Since ownCloud 5 it is possible to let web servers handle static file serving.
This should generally improve performance (web servers are optimized for this) and in some cases permits controlled
file serving (i.e. pause and resume downloads).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This feature can currently only be activated for local files, i.e. files inside the <strong>data/</strong> directory and local mounts.  It also does not work with the Encryption App enabled.
Controlled file serving <strong>does not work for generated zip files</strong>. This is due to zip files being generated and streamed back directly to the client.</p>
</div>
<div class="section" id="apache2-x-sendfile">
<h2>Apache2 (X-Sendfile)<a class="headerlink" href="#apache2-x-sendfile" title="Permalink to this headline">¶</a></h2>
<p>It is possible to let Apache handle static file serving via <a class="reference external" href="https://tn123.org/mod_xsendfile/">mod_xsendfile</a>.</p>
<div class="section" id="installation">
<h3>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h3>
<p>On Debian and Ubuntu systems use:</p>
<div class="highlight-bash"><div class="highlight"><pre>apt-get install libapache2-mod-xsendfile
</pre></div>
</div>
</div>
<div class="section" id="configuration">
<h3>Configuration<a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h3>
<p>Configuration of mod_xsendfile for ownCloud depends on its version.
For versions below 0.10 (Debian squeeze ships with 0.9)</p>
<div class="highlight-xml"><pre>&lt;Directory /var/www/owncloud&gt;
    ...
    SetEnv MOD_X_SENDFILE_ENABLED 1
    XSendFile On
    XSendFileAllowAbove On
&lt;/Directory&gt;</pre>
</div>
<p>For versions &gt;=0.10 (e.g. Ubuntu 12.10)</p>
<div class="highlight-xml"><pre>&lt;Directory /var/www/owncloud&gt;
    ...
    SetEnv MOD_X_SENDFILE_ENABLED 1
    XSendFile On
    XSendFilePath /home/valerio
&lt;/Directory&gt;</pre>
</div>
<ul class="simple">
<li><strong>SetEnv MOD_X_SENDFILE_ENABLED</strong>: tells ownCloud scripts that they should add the X-Sendfile header when serving files</li>
<li><strong>XSendFile</strong>: enables web server handling of X-Sendfile headers (and therefore file serving) for the specified Directory</li>
<li><strong>XSendFileAllowAbove (&lt;0.10)</strong>: enables file serving through web server on path outside the specified Directory. This is needed for configured local mounts which may reside outside data directory</li>
<li><strong>XSendFilePath (&gt;=0.10)</strong>: a white list of paths that the web server is allowed to serve outside of the specified Directory. Other paths which correspond to local mounts should be configured here as well. For a more in-depth documentation of this directive refer to mod_xsendfile website linked above</li>
</ul>
</div>
</div>
<div class="section" id="lighttpd-x-sendfile2">
<h2>LigHTTPd (X-Sendfile2)<a class="headerlink" href="#lighttpd-x-sendfile2" title="Permalink to this headline">¶</a></h2>
<p>LigHTTPd uses similar headers to Apache2, apart from the fact that it does not handle partial downloads in the same way
Apache2 does. For this reason, a different method is used for LigHTTPd.</p>
<div class="section" id="id1">
<h3>Installation<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>X-Sendfile and X-Sendfile2 are supported by default in LigHTTPd and no additional operation should be needed to install it.</p>
</div>
<div class="section" id="id2">
<h3>Configuration<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<p>Your server configuration should include the following statements:</p>
<div class="highlight-python"><pre>fastcgi.server          = ( ".php" =&gt; ((
   ...
   "allow-x-send-file" =&gt; "enable",
   "bin-environment" =&gt; (
      "MOD_X_SENDFILE2_ENABLED" =&gt; "1",
   ),
)))</pre>
</div>
<ul class="simple">
<li><strong>allow-x-send-file</strong>: enables LigHTTPd to use X-Sendfile and X-Sendfile2 headers to serve files</li>
<li><strong>bin-environment</strong>: is used to parse MOD_X_SENDFILE2_ENABLED to the ownCloud backend, to make it use the X-Sendfile and X-Sendfile2 headers in it&#8217;s response</li>
</ul>
</div>
</div>
<div class="section" id="nginx-x-accel-redirect">
<h2>Nginx (X-Accel-Redirect)<a class="headerlink" href="#nginx-x-accel-redirect" title="Permalink to this headline">¶</a></h2>
<p>Nginx supports handling of static files differently from Apache. Documentation can be found in the Nginx Wiki
section <a class="reference external" href="http://wiki.nginx.org/XSendfile">Mod X-Sendfile</a> and section <a class="reference external" href="http://wiki.nginx.org/X-accel">X-Accell</a>.
The header used by Nginx is X-Accel-Redirect.</p>
<div class="section" id="id3">
<h3>Installation<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
<p>X-Accel-Redirect is supported by default in Nginx and no additional operation should be needed to install it.</p>
</div>
<div class="section" id="id4">
<h3>Configuration<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h3>
<p>Configuration is similar to Apache:</p>
<div class="highlight-python"><pre>location ~ \.php(?:$|/) {
    ...
    fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
}

location ^~ /data {
    internal;
    # Set 'alias' if not using the default 'datadirectory'
    #alias /path/to/non-default/datadirectory;

#    LOCAL-MOUNT-NAME should match "Folder name" and 'alias' value should match "Configuration"
#    A 'Local' External Storage Mountpoint available to a single user
#    location /data/USER/files/LOCAL-FS-MOUNT-NAME {
#        alias /path/to/local-mountpoint;
#    }

#    A 'Local' External Storage Mountpoint available to mulitple users
#    location ~ ^/data/(?:USER1|USER2)/files/LOCAL-FS-MOUNT-NAME/(.+)$ {
#        alias /path/to/local-mountpoint/$1;
#    }

#    A 'Local' External Storage Mountpoint available to all users
#    location ~ ^/data/[^/]+/files/LOCAL-FS-MOUNT-NAME/(.+)$ {
#        alias /path/to/local-mountpoint/$1;
#    }

}</pre>
</div>
<ul class="simple">
<li><strong>fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED</strong> ~ Tells ownCloud scripts that they should add the X-Accel-Redirect header when serving files.</li>
<li><strong>/data</strong> ~ The ownCloud data directory.  Any &#8216;Local&#8217; External Storage Mounts must also have nested locations here.<ul>
<li>set alias if you are using a non-default data directory</li>
<li><strong>/data/USER/files/LOCAL-MOUNT-NAME</strong> ~ a local external storage mount available to a single user</li>
<li><strong>~ ^/data/(?:USER1|USER2)/files/LOCAL-MOUNT-NAME/(.+)$</strong> ~ a local external storage mount available to multiple users</li>
<li><strong>~ ^/data/[^/]+/files/LOCAL-MOUNT-NAME/(.+)$</strong> ~ a local external storage mount available to all users</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="section" id="how-to-check-if-it-s-working">
<h2>How to check if it&#8217;s working?<a class="headerlink" href="#how-to-check-if-it-s-working" title="Permalink to this headline">¶</a></h2>
<p>You are still able to download stuff via the web interface and single, local file downloads can be paused and resumed.</p>
</div>
</div>


					</div>
				</div>
			</div>
    
  </div>
</div>
  </body>
</html>