<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gog&#039;s info &#187; nginx</title>
	<atom:link href="http://gogs.info/tag/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://gogs.info</link>
	<description></description>
	<lastBuildDate>Wed, 27 Apr 2011 15:02:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Set filenames with Nginx secure download module</title>
		<link>http://gogs.info/2010/03/set-filenames-with-nginx-secure-download-module/</link>
		<comments>http://gogs.info/2010/03/set-filenames-with-nginx-secure-download-module/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 16:34:40 +0000</pubDate>
		<dc:creator>Goran Jurić</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://gogs.info/?p=116</guid>
		<description><![CDATA[When we switched from Lighttpd to Nginx a couple of months ago we were faced with an annoying problem. Paying subscribers to our site have an option of downloading PDF files of the magazine. With Lighttpd we were using mod_secdownload to provide this functionality without exposing the files to the public. We compiled Nginx with [...]]]></description>
			<content:encoded><![CDATA[<p>When we switched from <a href="http://www.lighttpd.net/">Lighttpd</a> to <a href="http://wiki.nginx.org/">Nginx</a> a couple of months ago we were faced with an annoying problem.</p>
<p>Paying subscribers to our site have an option of downloading PDF files of the magazine. With Lighttpd we were using <a href="http://redmine.lighttpd.net/wiki/lighttpd/docs:modsecdownload">mod_secdownload</a> to provide this functionality without exposing the files to the public. We compiled Nginx with the <a href="http://wiki.nginx.org/NginxHttpSecureDownload">secure_download_module</a> and it kinda worked.</p>
<p>Files were downloading as expected but the file names where all messed up. Download links where generated for each user and they looked something like this: <em>/pdf/645.pdf/097ac16cb19ff6c163d6f813fdd44b4d/4b283bfa</em> and the browser saved the file to the users hard drive with the file name of <em>4b283bfa</em>. Since the file name didn&#8217;t have an extension it was impossible for the OS to know that is has to use a PDF reader to open the file.</p>
<p>Finally we managed to force the file name to the browser (download client) with a configuration directive that looks something like this:</p>
<pre class="bash"><span class="co0"># PDF download</span>
 location <span class="sy0">/</span>pdf <span class="br0">&#123;</span>
    secure_download on;
    secure_download_secret <span class="re1">$request_addr</span>;
    secure_download_path_mode <span class="kw2">file</span>;
    root <span class="sy0">/</span>path<span class="sy0">/</span>to<span class="sy0">/</span>dir<span class="sy0">/</span>with<span class="sy0">/</span>pdfs

    <span class="co0"># Extract the name of the PDF</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$uri</span> ~ <span class="st0">&quot;^/pdf/(.+\.pdf)$&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">set</span> <span class="re1">$filename</span> <span class="re4">$1</span>;
    <span class="br0">&#125;</span>

    <span class="co0"># Set appropriate headers</span>
    add_header Content-Disposition <span class="st0">&quot;attachment; filename=<span class="es2">$filename</span>&quot;</span>;
 <span class="br0">&#125;</span></pre>
<p>And that&#8217;s all there is to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://gogs.info/2010/03/set-filenames-with-nginx-secure-download-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

