<?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>Case &#187; nginx</title>
	<atom:link href="http://case.net.ru/tag/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://case.net.ru</link>
	<description>Just another technical weblog</description>
	<lastBuildDate>Sun, 29 Jan 2012 08:48:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ngx_http_secure_download</title>
		<link>http://case.net.ru/2011/01/06/ngx_http_secure_download/</link>
		<comments>http://case.net.ru/2011/01/06/ngx_http_secure_download/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 13:40:16 +0000</pubDate>
		<dc:creator>Case</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://case.net.ru/?p=781</guid>
		<description><![CDATA[Задача: обеспечить возможность скачивать контент с сервера. только посетителям вашего сайта. Реализация: использование специальных ссылок, которые содержат ключ и дату протухания. Модуль к nginx &#8211; ngx_http_secure_download Сборка nginx: $ cd nginx-0.8.53 $ ./configure --add-module=../ngx_http_secure_download/ Конфиг nginx: location /somefolder &#123; secure_download on; secure_download_secret IAmSalt$remote_addr; secure_download_path_mode file; &#160; if &#40;$secure_download = &#34;-1&#34;&#41; &#123; rewrite /expired.html break; &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>Задача: обеспечить возможность скачивать контент с сервера. только посетителям вашего сайта.</p>
<p>Реализация: использование специальных ссылок, которые содержат ключ и дату протухания.</p>
<p>Модуль к nginx &#8211; <a href="https://github.com/replay/ngx_http_secure_download">ngx_http_secure_download</a></p>
<p>Сборка nginx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> nginx-0.8.53
$ .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--add-module</span>=..<span style="color: #000000; font-weight: bold;">/</span>ngx_http_secure_download<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Конфиг nginx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">        location <span style="color: #000000; font-weight: bold;">/</span>somefolder <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            secure_download on;
            secure_download_secret IAmSalt<span style="color: #007800;">$remote_addr</span>;
            secure_download_path_mode <span style="color: #c20cb9; font-weight: bold;">file</span>;
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$secure_download</span> = <span style="color: #ff0000;">&quot;-1&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                rewrite <span style="color: #000000; font-weight: bold;">/</span>expired.html <span style="color: #7a0874; font-weight: bold;">break</span>;
            <span style="color: #7a0874; font-weight: bold;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$secure_download</span> = <span style="color: #ff0000;">&quot;-2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                rewrite <span style="color: #000000; font-weight: bold;">/</span>bad_hash.html <span style="color: #7a0874; font-weight: bold;">break</span>;
            <span style="color: #7a0874; font-weight: bold;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$secure_download</span> = <span style="color: #ff0000;">&quot;-3&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">500</span>;
            <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
            rewrite ^<span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9a-zA-Z<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-9a-zA-Z<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*</span>$ $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">break</span>; <span style="color: #000000; font-weight: bold;">//</span> crop all the <span style="color: #000000; font-weight: bold;">/</span>hash<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight: bold;">time</span> stuff off the url
        <span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Генерация ссылки средствами php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> secure_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$ts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$ts_in_hex</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dechex</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$secret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'IAmSalt'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$secret</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ts_in_hex</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span>  <span style="color: #000088;">$url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$hash</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ts_in_hex</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Использованы материалы статьи: <a href="http://habrahabr.ru/blogs/video/111249/">Видеохостинг своими руками</a></p>
<p>PS: Так же, есть модуль <a href="http://sysoev.ru/nginx/docs/http/ngx_http_secure_link_module.html">ngx_http_secure_link_module</a>, но у него все ссылки перманентные.</p>
]]></content:encoded>
			<wfw:commentRss>http://case.net.ru/2011/01/06/ngx_http_secure_download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Установка nginx и php_fastcgi</title>
		<link>http://case.net.ru/2009/02/01/nginx-fastcgi/</link>
		<comments>http://case.net.ru/2009/02/01/nginx-fastcgi/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 11:10:20 +0000</pubDate>
		<dc:creator>Case</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://case.net.ru/?p=171</guid>
		<description><![CDATA[Променяли apache на nginx + fastcgi. Замечания: - наверное должно работать быстрее - в отличии от апачевских rewrite&#8217;ов &#8211; в nginx&#8217;овских вначале должно стоять ^/, а не просто ^ - красивый конфиг где все понятно - под php надобно демона запускать, вот скриптик: 1 2 3 4 5 6 7 8 9 10 11 12 [...]]]></description>
			<content:encoded><![CDATA[<p>Променяли apache на nginx + fastcgi. Замечания:<br />
- наверное должно работать быстрее<br />
- в отличии от апачевских rewrite&#8217;ов &#8211; в nginx&#8217;овских вначале должно стоять ^/, а не просто ^<br />
- красивый конфиг где все понятно<br />
- под php надобно демона запускать, вот скриптик:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># PROVIDE: php_fastcgi</span>
<span style="color: #666666; font-style: italic;"># REQUIRE: DAEMON</span>
<span style="color: #666666; font-style: italic;"># BEFORE:  LOGIN</span>
<span style="color: #666666; font-style: italic;"># KEYWORD: shutdown</span>
&nbsp;
. <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.subr
&nbsp;
<span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;php_fastcgi&quot;</span>
<span style="color: #007800;">rcvar</span>=<span style="color: #000000; font-weight: bold;">`</span>set_rcvar<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
load_rc_config <span style="color: #007800;">$name</span>
&nbsp;
: <span style="color: #800000;">${php_fastcgi_enable=&quot;NO&quot;}</span>
: <span style="color: #800000;">${php_fastcgi_user=&quot;www&quot;}</span>
: <span style="color: #800000;">${php_fastcgi_bindaddr=&quot;127.0.0.1&quot;}</span>
: <span style="color: #800000;">${php_fastcgi_bindport=&quot;9000&quot;}</span>
: <span style="color: #800000;">${php_fastcgi_children=&quot;5&quot;}</span>
: <span style="color: #800000;">${php_fastcgi_max_requests=&quot;1000&quot;}</span>
: <span style="color: #800000;">${php_fastcgi_allowed_env=&quot;&quot;}</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PHP_FCGI_CHILDREN</span>=<span style="color: #800000;">${php_fastcgi_children}</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PHP_FCGI_MAX_REQUESTS</span>=<span style="color: #800000;">${php_fastcgi_max_requests}</span>
&nbsp;
<span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">command</span></span>=<span style="color: #ff0000;">&quot;/usr/local/bin/php-cgi&quot;</span>
<span style="color: #007800;">command_args</span>=<span style="color: #ff0000;">&quot;-q -b <span style="color: #007800;">${php_fastcgi_bindaddr}</span>:<span style="color: #007800;">${php_fastcgi_bindport}</span> &amp;&quot;</span>
<span style="color: #007800;">pidfile</span>=<span style="color: #ff0000;">&quot;/var/run/<span style="color: #007800;">${name}</span>.pid&quot;</span>
&nbsp;
<span style="color: #007800;">_allowed_env</span>=<span style="color: #ff0000;">&quot;ORACLE_HOME PATH USER PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS&quot;</span>
<span style="color: #007800;">_allowed_env</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${_allowed_env}</span> <span style="color: #007800;">${php_fastcgi_allowed_env}</span>&quot;</span>
&nbsp;
<span style="color: #007800;">start_precmd</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${name}</span>_start_precmd&quot;</span>
<span style="color: #007800;">start_postcmd</span>=<span style="color: #ff0000;">&quot;ps -U <span style="color: #007800;">${php_fastcgi_user}</span> -o 'pid,command'|grep <span style="color: #007800;">${command}</span>|head -1|cut -f 1 -d ' ' &gt; <span style="color: #007800;">${pidfile}</span>&quot;</span>
<span style="color: #007800;">stop_postcmd</span>=<span style="color: #ff0000;">&quot;: &gt; <span style="color: #007800;">${pidfile}</span>&quot;</span>
php_fastcgi_start_precmd<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">USER</span>=<span style="color: #800000;">${php_fastcgi_user}</span>
    <span style="color: #007800;">E</span>=
    <span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${_allowed_env}</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #007800;">_val</span>=<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\$</span><span style="color: #007800;">$i</span>&quot;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${_val}</span>_x&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;_x&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #007800;">_add</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>=<span style="color: #007800;">$_val</span>&quot;</span>
            <span style="color: #007800;">E</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${E}</span> <span style="color: #007800;">${_add}</span>&quot;</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">done</span>
    <span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">command</span></span>=<span style="color: #ff0000;">&quot;env - <span style="color: #007800;">${E}</span> <span style="color: #007800;">${command}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
load_rc_config <span style="color: #007800;">$name</span>
&nbsp;
run_rc_command <span style="color: #ff0000;">&quot;$1&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://case.net.ru/2009/02/01/nginx-fastcgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
