Your IP : 216.73.217.64
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NGINX Example Configurations — ownCloud 10.0.1 Server Administration Manual 10.0.1 documentation</title>
<link rel="stylesheet" href="../_static/" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/main.min.css" type="text/css" />
<link rel="stylesheet" href="../_static/styles.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '10.0.1',
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/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="../_static/js/jquery-fix.js"></script>
<script type="text/javascript" src="../_static/bootstrap-3.1.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../_static/bootstrap-sphinx.js"></script>
<link rel="top" title="ownCloud 10.0.1 Server Administration Manual 10.0.1 documentation" href="../contents.html" />
<link rel="up" title="Installation" href="index.html" />
<link rel="next" title="Database Configuration" href="../configuration_database/index.html" />
<link rel="prev" title="SELinux Configuration" href="selinux_configuration.html" />
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="theme-color" content="#1d2d44">
</head>
<body role="document">
<div class="wrap container not-front">
<div class="content row">
<main class="main">
<div class="row page-content-header">
<div class="col-md-5 col-md-offset-7">
<form class="headersearch" style="margin-bottom:-3px;" action="../search.html" method="get">
<input type="text" value="" name="q" id="q" class="form-control" />
<button class="btn btn-default" type="submit" id="searchsubmit">Search</button>
</form>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="sidebar">
<div class="menu-support-container">
<ul id="menu-support" class="menu">
<ul>
<li><a href="../contents.html">Table of Contents</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../release_notes.html">Release Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../whats_new_admin.html">What’s New in ownCloud 10.0.1</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Installation</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="system_requirements.html">System Requirements</a></li>
<li class="toctree-l2"><a class="reference internal" href="deployment_recommendations.html">ownCloud Deployment Recommendations</a></li>
<li class="toctree-l2"><a class="reference internal" href="linux_installation.html">Preferred Linux Installation Method</a></li>
<li class="toctree-l2"><a class="reference internal" href="installation_wizard.html">Installation Wizard</a></li>
<li class="toctree-l2"><a class="reference internal" href="command_line_installation.html">Installing ownCloud from the Command Line</a></li>
<li class="toctree-l2"><a class="reference internal" href="changing_the_web_route.html">Changing Your ownCloud URL</a></li>
<li class="toctree-l2"><a class="reference internal" href="apps_management_installation.html">Installing and Managing Apps</a></li>
<li class="toctree-l2"><a class="reference internal" href="apps_supported.html">Supported Apps in ownCloud</a></li>
<li class="toctree-l2"><a class="reference internal" href="source_installation.html">Manual Installation on Linux</a></li>
<li class="toctree-l2"><a class="reference internal" href="appliance_installation.html">ownCloud Community Appliance</a></li>
<li class="toctree-l2"><a class="reference internal" href="selinux_configuration.html">SELinux Configuration</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="">NGINX Example Configurations</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#example-configurations">Example Configurations</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_database/index.html">Database Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_files/index.html">File Sharing and Management</a></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="../configuration_mimetypes/index.html">Mimetypes Management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_server/index.html">Server Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_user/index.html">User Management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../issues/index.html">Issues and Troubleshooting</a></li>
<li class="toctree-l1"><a class="reference internal" href="../enterprise/index.html">Enterprise Features</a></li>
</ul>
</ul>
</div>
</div>
</div>
<div class="col-md-9">
<div class="page-content">
<ul class="prevnext-title list-unstyled list-inline">
<li class="prev">
<a href="selinux_configuration.html" title="Previous Chapter: SELinux Configuration"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm">« SELinux Confi...</span>
</a>
</li>
<li class="next">
<a href="../configuration_database/index.html" title="Next Chapter: Database Configuration"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm">Database Conf... »</span>
</a>
</li>
</ul>
<div class="section" id="nginx-example-configurations">
<h1>NGINX Example Configurations<a class="headerlink" href="#nginx-example-configurations" title="Permalink to this headline">¶</a></h1>
<p>This page covers example NGINX configurations to use with running an ownCloud
server. Note that NGINX is not officially supported, and this page is
community-maintained. (Thank you, contributors!)</p>
<ul class="simple">
<li>You need to insert the following code into <strong>your NGINX configuration file.</strong></li>
<li>The configuration assumes that ownCloud is installed in
<code class="docutils literal"><span class="pre">/var/www/owncloud</span></code> and that it is accessed via
<code class="docutils literal"><span class="pre">http(s)://cloud.example.com</span></code>.</li>
<li>Adjust <strong>server_name</strong>, <strong>root</strong>, <strong>ssl_certificate</strong> and
<strong>ssl_certificate_key</strong> to suit your needs.</li>
<li>Make sure your SSL certificates are readable by the server (see <a class="reference external" href="http://wiki.nginx.org/HttpSslModule">NGINX HTTP
SSL Module documentation</a>).</li>
<li><code class="docutils literal"><span class="pre">add_header</span></code> statements are only taken from the current level and are not
cascaded from or to a different level. All necessary <code class="docutils literal"><span class="pre">add_header</span></code>
statements must be defined in each level needed. For better readability it
is possible to move <em>common</em> add header statements into a separate file
and include that file wherever necessary. However, each <code class="docutils literal"><span class="pre">add_header</span></code>
statement must be written in a single line to prevent connection problems
with sync clients.</li>
</ul>
<div class="section" id="example-configurations">
<h2>Example Configurations<a class="headerlink" href="#example-configurations" title="Permalink to this headline">¶</a></h2>
<p>Be careful about line breaks if you copy the examples, as long lines may be broken
for page formatting.</p>
<p>Thanks to <a class="reference external" href="https://github.com/josh4trunks">@josh4trunks</a> for providing /
creating these configuration examples.</p>
<p>You can use ownCloud over plain http, but we strongly encourage you to use
SSL/TLS to encrypt all of your server traffic, and to protect user’s logins and
data in transit.</p>
<ul class="simple">
<li>Remove the server block containing the redirect</li>
<li>Change <strong>listen 443 ssl</strong> to <strong>listen 80;</strong></li>
<li>Remove <strong>ssl_certificate</strong> and <strong>ssl_certificate_key</strong>.</li>
<li>Remove <strong>fastcgi_params HTTPS on;</strong></li>
</ul>
<div class="section" id="owncloud-in-the-webroot-of-nginx">
<h3>ownCloud in the webroot of NGINX<a class="headerlink" href="#owncloud-in-the-webroot-of-nginx" title="Permalink to this headline">¶</a></h3>
<p>The following config should be used when ownCloud is placed in the webroot of
your NGINX installation.</p>
<div class="highlight-python"><div class="highlight"><pre>upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name cloud.example.com;
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name cloud.example.com;
ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;
# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this topic first.
#add_header Strict-Transport-Security "max-age=15552000; includeSubDomains";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Path to the root of your installation
root /var/www/owncloud/;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
location ^~ /.well-known/acme-challenge { }
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Disable gzip to avoid the removal of the ETag header
gzip off;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location / {
rewrite ^ /index.php$uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
return 404;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
return 404;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off; #Available since NGINX 1.7.11
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri $uri/ =404;
index index.php;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "max-age=15778463";
# Add headers to serve security related headers (It is intended to have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into this topic first.
#add_header Strict-Transport-Security "max-age=15552000; includeSubDomains";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Optional: Don't log access to assets
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
</pre></div>
</div>
</div>
<div class="section" id="owncloud-in-a-subdir-of-nginx">
<h3>ownCloud in a subdir of NGINX<a class="headerlink" href="#owncloud-in-a-subdir-of-nginx" title="Permalink to this headline">¶</a></h3>
<p>The following config should be used when ownCloud is not in your webroot but placed under a different contextroot of your NGINX installation such as /owncloud or /cloud. The following configuration assumes it is placed under <code class="docutils literal"><span class="pre">/owncloud</span></code> and that you have <code class="docutils literal"><span class="pre">'overwritewebroot'</span> <span class="pre">=></span> <span class="pre">'/owncloud',</span></code> set in your <code class="docutils literal"><span class="pre">config/config.php</span></code>.</p>
<div class="highlight-python"><div class="highlight"><pre>upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php7-fpm.sock;
}
server {
listen 80;
server_name cloud.example.com;
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name cloud.example.com;
ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "-ALL:EECDH+AES256:EDH+AES256:AES256-SHA:EECDH+AES:EDH+AES:!ADH:!NULL:!aNULL:!eNULL:!EXPORT:!LOW:!MD5:!3DES:!PSK:!SRP:!DSS:!AESGCM:!RC4";
ssl_dhparam /etc/nginx/dh4096.pem;
ssl_prefer_server_ciphers on;
keepalive_timeout 70;
ssl_stapling on;
ssl_stapling_verify on;
# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this topic first.
#add_header Strict-Transport-Security "max-age=15552000; includeSubDomains";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Path to the root of your installation
root /var/www/;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /owncloud/public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /owncloud/public.php?service=host-meta-json last;
location = /.well-known/carddav {
return 301 $scheme://$host/owncloud/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/owncloud/remote.php/dav;
}
location /.well-known/acme-challenge { }
location ^~ /owncloud {
root /var/www/owncloud/;
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Disable gzip to avoid the removal of the ETag header
gzip off;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
error_page 403 /owncloud/core/templates/403.php;
error_page 404 /owncloud/core/templates/404.php;
location /owncloud {
rewrite ^ /owncloud/index.php$uri;
}
location ~ ^/owncloud/(?:build|tests|config|lib|3rdparty|templates|data)/ {
return 404;
}
location ~ ^/owncloud/(?:\.|autotest|occ|issue|indie|db_|console) {
return 404;
}
location ~ ^/owncloud/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
fastcgi_split_path_info ^/owncloud(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name; # necessary for owncloud to detect the contextroot https://github.com/owncloud/core/blob/master/lib/private/AppFramework/Http/Request.php#L597
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
# EXPERIMENTAL: active the following if you need to get rid of the 'index.php' in the URLs
#fastcgi_param front_controller_active true;
fastcgi_read_timeout 180; # increase default timeout e.g. for long running carddav/ caldav syncs with 1000+ entries
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off; #Available since NGINX 1.7.11
}
location ~ ^/owncloud/(?:updater|ocs-provider)(?:$|/) {
try_files $uri $uri/ =404;
index index.php;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* /owncloud(\/.*\.(?:css|js)) {
try_files $1 /owncloud/index.php$1$is_args$args;
add_header Cache-Control "max-age=15778463";
# Add headers to serve security related headers (It is intended to have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into this topic first.
#add_header Strict-Transport-Security "max-age=15552000; includeSubDomains";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Optional: Don't log access to assets
access_log off;
}
location ~* /owncloud(/.*\.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg|map)) {
try_files $1 /owncloud/index.php$1$is_args$args;
add_header Cache-Control "public, max-age=7200";
# Optional: Don't log access to other assets
access_log off;
}
}
}
</pre></div>
</div>
</div>
<div class="section" id="suppressing-log-messages">
<h3>Suppressing Log Messages<a class="headerlink" href="#suppressing-log-messages" title="Permalink to this headline">¶</a></h3>
<p>If you’re seeing meaningless messages in your logfile, for example <a class="reference external" href="https://central.owncloud.org/t/htaccesstest-txt-errors-in-logfiles/831">client
denied by server configuration: /var/www/data/htaccesstest.txt</a>,
add this section to your NGINX configuration to suppress them:</p>
<div class="highlight-python"><div class="highlight"><pre>location = /data/htaccesstest.txt {
allow all;
log_not_found off;
access_log off;
}
</pre></div>
</div>
</div>
<div class="section" id="javascript-js-or-css-css-files-not-served-properly">
<h3>JavaScript (.js) or CSS (.css) files not served properly<a class="headerlink" href="#javascript-js-or-css-css-files-not-served-properly" title="Permalink to this headline">¶</a></h3>
<p>A common issue with custom NGINX configs is that JavaScript (.js)
or CSS (.css) files are not served properly leading to a 404 (File not found)
error on those files and a broken webinterface.</p>
<p>This could be caused by the:</p>
<div class="highlight-python"><div class="highlight"><pre>location ~* \.(?:css|js)$ {
</pre></div>
</div>
<p>block shown above not located <strong>below</strong> the:</p>
<div class="highlight-python"><div class="highlight"><pre>location ~ \.php(?:$|/) {
</pre></div>
</div>
<p>block. Other custom configurations like caching JavaScript (.js)
or CSS (.css) files via gzip could also cause such issues.</p>
</div>
<div class="section" id="not-all-of-my-contacts-are-synchronized">
<h3>Not all of my contacts are synchronized<a class="headerlink" href="#not-all-of-my-contacts-are-synchronized" title="Permalink to this headline">¶</a></h3>
<p>Check your server timeouts! It turns out that CardDAV sync often fails silently if the request runs into timeouts. With PHP-FPM you might see a “CoreDAVHTTPStatusErrorDomain error 504” which is an “HTTP504 Gateway timeout” error. To solve this, first check the <code class="docutils literal"><span class="pre">default_socket_timeout</span></code> setting in <code class="docutils literal"><span class="pre">/etc/php/7.0/fpm/php.ini</span></code> and increase the above <code class="docutils literal"><span class="pre">fastcgi_read_timeout</span></code> accordingly. Depending on your server’s performance a timeout of 180s should be sufficient to sync an addressbook of ~1000 contacts.</p>
</div>
<div class="section" id="performance-tuning">
<h3>Performance Tuning<a class="headerlink" href="#performance-tuning" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://nginx.org/en/docs/http/ngx_http_spdy_module.html">nginx (<1.9.5) <ngx_http_spdy_module</a>
<a class="reference external" href="http://nginx.org/en/docs/http/ngx_http_v2_module.html">nginx (+1.9.5) <ngx_http_http2_module</a></p>
<p>To use http_v2 for NGINX you have to check two things:</p>
<blockquote>
<div><p>1.) be aware that this module is not built in by default due to a dependency
to the openssl version used on your system. It will be enabled with the
<code class="docutils literal"><span class="pre">--with-http_v2_module</span></code> configuration parameter during compilation. The
dependency should be checked automatically. You can check the presence of
http_v2 with <code class="docutils literal"><span class="pre">nginx</span> <span class="pre">-V</span> <span class="pre">2>&1</span> <span class="pre">|</span> <span class="pre">grep</span> <span class="pre">http_v2</span> <span class="pre">-o</span></code>. An example of how to
compile NGINX can be found in section “Configure NGINX with the
<code class="docutils literal"><span class="pre">nginx-cache-purge</span></code> module” below.</p>
<p>2.) When you have used SPDY before, the NGINX config has to be changed from
<code class="docutils literal"><span class="pre">listen</span> <span class="pre">443</span> <span class="pre">ssl</span> <span class="pre">spdy;</span></code> to <code class="docutils literal"><span class="pre">listen</span> <span class="pre">443</span> <span class="pre">ssl</span> <span class="pre">http2;</span></code></p>
</div></blockquote>
</div>
<div class="section" id="nginx-caching-owncloud-gallery-thumbnails">
<h3>NGINX: caching ownCloud gallery thumbnails<a class="headerlink" href="#nginx-caching-owncloud-gallery-thumbnails" title="Permalink to this headline">¶</a></h3>
<p>One of the optimizations for ownCloud when using NGINX as the Web server is to
combine FastCGI caching with “Cache Purge”, a <a class="reference external" href="http://wiki.nginx.org/3rdPartyModules">3rdparty NGINX module</a> that adds the ability to purge
content from <cite>FastCGI</cite>, <cite>proxy</cite>, <cite>SCGI</cite> and <cite>uWSGI</cite> caches. This mechanism
speeds up thumbnail presentation as it shifts requests to NGINX and minimizes
php invocations which otherwise would take place for every thumbnail presented
every time.</p>
<p>The following procedure is based on an Ubuntu 14.04 system. You may need to
adapt it according your OS type and release.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Unlike Apache, NGINX does not dynamically load modules. All modules needed
must be compiled into NGINX. This is one of the reasons for NGINX´s
performance. It is expected to have an already running NGINX installation
with a working configuration set up as described in the ownCloud
documentation.</p>
</div>
</div>
<div class="section" id="nginx-module-check">
<h3>NGINX module check<a class="headerlink" href="#nginx-module-check" title="Permalink to this headline">¶</a></h3>
<p>As a first step, it is necessary to check if your NGINX installation has the
<code class="docutils literal"><span class="pre">nginx</span> <span class="pre">cache</span> <span class="pre">purge</span></code> module compiled in:</p>
<div class="highlight-python"><div class="highlight"><pre>nginx -V 2>&1 | grep ngx_cache_purge -o
</pre></div>
</div>
<p>If your output contains <code class="docutils literal"><span class="pre">ngx_cache_purge</span></code>, you can continue with the
configuration, otherwise you need to manually compile NGINX with the module
needed.</p>
</div>
<div class="section" id="compile-nginx-with-the-nginx-cache-purge-module">
<h3>Compile NGINX with the <code class="docutils literal"><span class="pre">nginx-cache-purge</span></code> module<a class="headerlink" href="#compile-nginx-with-the-nginx-cache-purge-module" title="Permalink to this headline">¶</a></h3>
<ol class="arabic simple">
<li><strong>Preparation:</strong></li>
</ol>
<div class="highlight-python"><div class="highlight"><pre>cd /opt
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
sudo vi /etc/apt/sources.list.d/nginx.list
</pre></div>
</div>
<p>Add the following lines (if different, replace <code class="docutils literal"><span class="pre">{trusty}</span></code> by your
distribution name):</p>
<div class="highlight-python"><div class="highlight"><pre>deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx
deb -src http://nginx.org/packages/mainline/ubuntu/ trusty nginx
</pre></div>
</div>
<p>Then run <code class="docutils literal"><span class="pre">sudo</span> <span class="pre">apt-get</span> <span class="pre">update</span></code></p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you’re not overly cautious and wish to install the latest and
greatest NGINX packages and features, you may have to install NGINX from its
mainline repository. From the NGINX homepage: “In general, you should
deploy NGINX from its mainline branch at all times.” If you would like to
use standard NGINX from the latest mainline branch but without compiling in
any additional modules, just run <code class="docutils literal"><span class="pre">sudo</span> <span class="pre">apt-get</span> <span class="pre">install</span> <span class="pre">nginx</span></code>.</p>
</div>
<ol class="arabic simple" start="2">
<li><strong>Download the NGINX source from the ppa repository</strong></li>
</ol>
<div class="highlight-python"><div class="highlight"><pre>cd /opt
sudo apt-get build-dep nginx
sudo apt-get source nginx
</pre></div>
</div>
<ol class="arabic simple" start="3">
<li><strong>Download module(s) to be compiled in and configure compiler arguments</strong></li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span class="n">ls</span> <span class="o">-</span><span class="n">la</span>
</pre></div>
</div>
<p>Please replace <code class="docutils literal"><span class="pre">{release}</span></code> with the release downloaded:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">cd</span> <span class="o">/</span><span class="n">opt</span><span class="o">/</span><span class="n">nginx</span><span class="o">-</span><span class="p">{</span><span class="n">release</span><span class="p">}</span><span class="o">/</span><span class="n">debian</span>
</pre></div>
</div>
<p>If folder “modules” is not present, do:</p>
<div class="highlight-python"><div class="highlight"><pre>sudo mkdir modules
cd modules
sudo git clone https://github.com/FRiCKLE/ngx_cache_purge.git
sudo vi /opt/nginx-{release}/debian/rules
</pre></div>
</div>
<p>If not present, add the following line at the top under:</p>
<div class="highlight-python"><div class="highlight"><pre>#export DH_VERBOSE=1:
MODULESDIR = $(CURDIR)/debian/modules
</pre></div>
</div>
<p>And at the end of every <code class="docutils literal"><span class="pre">configure</span></code> command add:</p>
<div class="highlight-python"><div class="highlight"><pre>--add-module=$(MODULESDIR)/ngx_cache_purge
</pre></div>
</div>
<p>Don’t forget to escape preceeding lines with a backslash <code class="docutils literal"><span class="pre">\</span></code>.
The parameters may now look like:</p>
<div class="highlight-python"><div class="highlight"><pre>--with-cc-opt="$(CFLAGS)" \
--with-ld-opt="$(LDFLAGS)" \
--with-ipv6 \
--add-module=$(MODULESDIR)/ngx_cache_purge
</pre></div>
</div>
<ol class="arabic simple" start="4">
<li><strong>Compile and install NGINX</strong></li>
</ol>
<div class="highlight-python"><div class="highlight"><pre>cd /opt/nginx-{release}
sudo dpkg-buildpackage -uc -b
ls -la /opt
sudo dpkg --install /opt/nginx_{release}~{distribution}_amd64.deb
</pre></div>
</div>
<ol class="arabic simple" start="5">
<li><strong>Check if the compilation and installation of the ngx_cache_purge module
was successful</strong></li>
</ol>
<div class="highlight-python"><div class="highlight"><pre>nginx -V 2>&1 | grep ngx_cache_purge -o
</pre></div>
</div>
<p>It should now show: <code class="docutils literal"><span class="pre">ngx_cache_purge</span></code></p>
<p>Show NGINX version including all features compiled and installed:</p>
<div class="highlight-python"><div class="highlight"><pre>nginx -V 2>&1 | sed s/" --"/"\n\t--"/g
</pre></div>
</div>
<ol class="arabic simple" start="6">
<li><strong>Mark NGINX to be blocked from further updates via apt-get</strong></li>
</ol>
<div class="highlight-python"><div class="highlight"><pre>sudo dpkg --get-selections | grep nginx
</pre></div>
</div>
<p>For every NGINX component listed run <code class="docutils literal"><span class="pre">sudo</span> <span class="pre">apt-mark</span> <span class="pre">hold</span> <span class="pre"><component></span></code></p>
<ol class="arabic simple" start="7">
<li><strong>Regular checks for NGINX updates</strong></li>
</ol>
<p>Do a regular visit on the <a class="reference external" href="http://nginx.org">NGINX news page</a> and proceed
in case of updates with items 2 to 5.</p>
</div>
<div class="section" id="configure-nginx-with-the-nginx-cache-purge-module">
<h3>Configure NGINX with the <code class="docutils literal"><span class="pre">nginx-cache-purge</span></code> module<a class="headerlink" href="#configure-nginx-with-the-nginx-cache-purge-module" title="Permalink to this headline">¶</a></h3>
<ol class="arabic simple">
<li><strong>Preparation</strong>
Create a directory where NGINX will save the cached thumbnails. Use any
path that fits to your environment. Replace <code class="docutils literal"><span class="pre">{path}</span></code> in this example with
your path created:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre>sudo mkdir -p /usr/local/tmp/cache
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><strong>Configuration</strong></li>
</ol>
<div class="highlight-python"><div class="highlight"><pre>sudo vi /etc/nginx/sites-enabled/{your-ownCloud-nginx-config-file}
</pre></div>
</div>
<p>Add at the <em>beginning</em>, but <em>outside</em> the <code class="docutils literal"><span class="pre">server{}</span></code> block:</p>
<div class="highlight-python"><div class="highlight"><pre># cache_purge
fastcgi_cache_path {path} levels=1:2 keys_zone=OWNCLOUD:100m inactive=60m;
map $request_uri $skip_cache {
default 1;
~*/thumbnail.php 0;
~*/apps/galleryplus/ 0;
~*/apps/gallery/ 0;
}
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Please adopt or delete any regex line in the <code class="docutils literal"><span class="pre">map</span></code> block according
your needs and the ownCloud version used.
As an alternative to mapping, you can use as many <code class="docutils literal"><span class="pre">if</span></code> statements in
your server block as necessary:</p>
<div class="last highlight-python"><div class="highlight"><pre>set $skip_cache 1;
if ($request_uri ~* "thumbnail.php") { set $skip_cache 0; }
if ($request_uri ~* "/apps/galleryplus/") { set $skip_cache 0; }
if ($request_uri ~* "/apps/gallery/") { set $skip_cache 0; }
</pre></div>
</div>
</div>
<p>Add <em>inside</em> the <code class="docutils literal"><span class="pre">server{}</span></code> block, as an example of a configuration:</p>
<div class="highlight-python"><div class="highlight"><pre># cache_purge (with $http_cookies we have unique keys for the user)
fastcgi_cache_key $http_cookie$request_method$host$request_uri;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
location ~ \.php(?:$/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_pass php-handler;
# cache_purge
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache OWNCLOUD;
fastcgi_cache_valid 60m;
fastcgi_cache_methods GET HEAD;
}
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Note regarding the <code class="docutils literal"><span class="pre">fastcgi_pass</span></code> parameter:
Use whatever fits your configuration. In the example above, an <code class="docutils literal"><span class="pre">upstream</span></code>
was defined in an NGINX global configuration file.
This may look like:</p>
<div class="last highlight-python"><div class="highlight"><pre>upstream php-handler {
server unix:/var/run/php5-fpm.sock;
# or
# server 127.0.0.1:9000;
}
</pre></div>
</div>
</div>
<ol class="arabic simple" start="3">
<li><strong>Test the configuration</strong></li>
</ol>
<div class="highlight-python"><div class="highlight"><pre>sudo nginx -s reload
</pre></div>
</div>
<ul class="simple">
<li>Open your browser and clear your cache.</li>
<li>Logon to your ownCloud instance, open the gallery app, move thru your
folders and watch while the thumbnails are generated for the first time.</li>
<li>You may also watch with eg. <code class="docutils literal"><span class="pre">htop</span></code> your system load while the
thumbnails are processed.</li>
<li>Go to another app or logout and relogon.</li>
<li>Open the gallery app again and browse to the folders you accessed before.
Your thumbnails should appear more or less immediately.</li>
<li><code class="docutils literal"><span class="pre">htop</span></code> will not show up additional load while processing, compared to
the high load before.</li>
</ul>
</div>
<div class="section" id="prevent-access-log-entries-when-accessing-thumbnails">
<h3>Prevent access log entries when accessing thumbnails<a class="headerlink" href="#prevent-access-log-entries-when-accessing-thumbnails" title="Permalink to this headline">¶</a></h3>
<p>When using Gallery or Galleryplus, any access to a thumbnail of a picture will be logged.
This can cause a massive log quanity making log reading challenging. With this approach,
you can disable access logging for those thumbnails.</p>
<ol class="arabic">
<li><p class="first"><strong>Create a map directive outside your server block like</strong></p>
<p>(Adopt the path queried according your needs.)</p>
</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre># do not access log to gallery thumbnails, flooding access logs only, error will be logged anyway
map $request_uri $loggable {
default 1;
~*\/apps\/gallery\/thumbnails 0;
~*\/apps\/galleryplus\/thumbnails 0;
}
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><strong>Inside your server block where you define your logs</strong></li>
</ol>
<div class="highlight-python"><div class="highlight"><pre>access_log /path-to-your-log combined if=$loggable;
</pre></div>
</div>
</div>
</div>
</div>
<ul class="prevnext-title list-unstyled list-inline">
<li class="prev">
<a href="selinux_configuration.html" title="Previous Chapter: SELinux Configuration"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm">« SELinux Confi...</span>
</a>
</li>
<li class="next">
<a href="../configuration_database/index.html" title="Next Chapter: Database Configuration"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm">Database Conf... »</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</main>
</div>
</div>
</body>
</html>