{"id":170115,"date":"2013-02-20T16:15:03","date_gmt":"2013-02-20T12:15:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=170115"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=170115","title":{"rendered":"<span class=\"post_title\">\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 nginx \u0432 chroot<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 <a href=\"http:\/\/habrahabr.ru\/qa\/34889\/\">\u0441\u0432\u043e\u0435\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/a> \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438, \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044f\u0442\u044c \u00ab\u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432\u00bb \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0438\u0445 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0436\u0435 \u043b\u043e\u043a\u0430\u043b\u0445\u043e\u0441\u0442 \u043e\u0442 \u0432\u0437\u043b\u043e\u043c\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b nginx \u0432 chroot&#8217;\u0435 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0441\u043a\u0440\u0438\u043f\u0442, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u0438\u044e\u0449\u0438\u0439 \u0441\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0432\u0437\u043b\u0430\u043c\u044b\u0432\u0430\u044e\u0442 \u0432\u0430\u0448 \u0441\u0435\u0440\u0432\u0435\u0440, \u0445\u0430\u0446\u043a\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u00abroot\u00bb, \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u0440\u043e\u043c\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e. \ud83d\ude42<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>nginx<\/h2>\n<p>  \u0421\u043e\u0431\u0438\u0440\u0430\u0442\u044c <b>nginx<\/b> + <b>openssl<\/b> + <b>pcre<\/b> + <b>zlib<\/b> \u0431\u0443\u0434\u0435\u043c \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432, \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0432\u0435\u0436\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<p>  \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0437\u0430\u0449\u0438\u0442 \u043e\u0442 \u0434\u0443\u0440\u0430\u043a\u0430, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u2014 \u0441\u043a\u0440\u0438\u043f\u0442 \u043b\u0438\u0448\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0440\u0443\u0442\u0438\u043d\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  <code>user@linux:~$ cat &lt;&lt; EOF &gt;&gt; ~\/chroot-nginx.sh<\/code>  <\/p>\n<pre><code class=\"bash\">main() {   local pkg_nginx=&quot;nginx-1.3.13&quot;   local pkg_openssl=&quot;openssl-1.0.1e&quot;   local pkg_pcre=&quot;pcre-8.32&quot;   local pkg_zlib=&quot;zlib-1.2.7&quot;    local build=&quot;$@&quot;    \/usr\/bin\/curl --remote-name &quot;http:\/\/nginx.org\/download\/${pkg_nginx}.tar.gz&quot;   \/usr\/bin\/curl --remote-name &quot;https:\/\/www.openssl.org\/source\/${pkg_openssl}.tar.gz&quot;   \/usr\/bin\/curl --remote-name &quot;ftp:\/\/ftp.csx.cam.ac.uk\/pub\/software\/programming\/pcre\/${pkg_pcre}.tar.bz2&quot;   \/usr\/bin\/curl --remote-name &quot;http:\/\/zlib.net\/${pkg_zlib}.tar.gz&quot;    \/bin\/tar --extract --file &quot;${pkg_nginx}.tar.gz&quot;   \/bin\/tar --extract --file &quot;${pkg_openssl}.tar.gz&quot;   \/bin\/tar --extract --file &quot;${pkg_pcre}.tar.bz2&quot;   \/bin\/tar --extract --file &quot;${pkg_zlib}.tar.gz&quot;    cd &quot;${pkg_nginx}&quot;    .\/configure \\     --user=&quot;http&quot; --group=&quot;http&quot; \\     --with-file-aio \\     --with-ipv6 \\     --with-openssl=&quot;..\/${pkg_openssl}&quot; --with-http_ssl_module \\     --with-pcre=&quot;..\/${pkg_pcre}&quot; --with-pcre-jit \\     --with-zlib=&quot;..\/${pkg_zlib}&quot; --with-http_gzip_static_module    make    mkdir --parents &quot;${build}&quot;    make DESTDIR=&quot;${build}&quot; install }<\/code><\/pre>\n<p><code>EOF<\/code><\/p>\n<h2>chroot<\/h2>\n<p>  \u0414\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 chroot-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0435\u043b\u0435\u0433\u0438\u0438 <b>root<\/b>, \u0442\u0430\u043a \u043a\u0430\u043a \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0444\u0430\u0439\u043b\u044b \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c nginx \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u044f 0-1024 \u043f\u043e\u0440\u0442\u043e\u0432 \u0431\u0435\u0437 \u043f\u0440\u0430\u0432 root.<\/p>\n<p>  <code>user@linux:~$ cat &lt;&lt; EOF &gt;&gt; ~\/chroot-nginx.sh<\/code>  <\/p>\n<pre><code class=\"bash\">as_root() {   local build=&quot;$@&quot;      cd &quot;${build}&quot; || return 0    mkdir &quot;.\/dev&quot;   mknod -m 0666 &quot;.\/dev\/null&quot; c 1 3   mknod -m 0666 &quot;.\/dev\/random&quot; c 1 8   mknod -m 0444 &quot;.\/dev\/urandom&quot; c 1 9    mkdir &quot;.\/etc&quot;   touch &quot;.\/etc\/shells&quot;    echo &quot;http:x:33:&quot; &gt;&gt; &quot;.\/etc\/group&quot;   echo &quot;nobody:x:99:&quot; &gt;&gt; &quot;.\/etc\/group&quot;    echo &quot;http:x:33:33:http:\/:\/bin\/false&quot; &gt;&gt; &quot;.\/etc\/passwd&quot;   echo &quot;nobody:x:99:99:nobody:\/:\/bin\/false&quot; &gt;&gt; &quot;.\/etc\/passwd&quot;    echo &quot;http:x:14871::::::&quot; &gt;&gt; &quot;.\/etc\/shadow&quot;   echo &quot;nobody:x:14871::::::&quot; &gt;&gt; &quot;.\/etc\/shadow&quot;    echo &quot;http:::&quot; &gt;&gt; &quot;.\/etc\/gshadow&quot;   echo &quot;nobody:::&quot; &gt;&gt; &quot;.\/etc\/gshadow&quot;    mkdir &quot;.\/usr\/lib&quot;    cp &quot;\/usr\/lib\/libnss_&quot;* &quot;.\/usr\/lib&quot;    ln -s &quot;usr\/lib&quot; &quot;.\/lib&quot;    local lib=&quot;&quot;   for lib in $(ldd &quot;.\/usr\/local\/nginx\/sbin\/nginx&quot; | grep -o &quot;[^ ]*\\\/lib[^ ]*&quot;); do     cp &quot;${lib}&quot; &quot;.${lib}&quot;   done    mkdir &quot;.\/usr\/local\/nginx\/client_body_temp&quot;   mkdir &quot;.\/usr\/local\/nginx\/proxy_temp&quot;   mkdir &quot;.\/usr\/local\/nginx\/scgi_temp&quot;   mkdir &quot;.\/usr\/local\/nginx\/uwsgi_temp&quot;   mkdir &quot;.\/usr\/local\/nginx\/fastcgi_temp&quot;    mkdir &quot;.\/tmp&quot;    chown -R &quot;root:root&quot; &quot;.&quot;    chown -R &quot;http:http&quot; &quot;.\/usr\/local\/nginx\/html&quot;   chown -R &quot;http:http&quot; &quot;.\/usr\/local\/nginx\/logs&quot;    chown &quot;http:http&quot; &quot;.\/usr\/local\/nginx\/client_body_temp&quot;   chown &quot;http:http&quot; &quot;.\/usr\/local\/nginx\/proxy_temp&quot;   chown &quot;http:http&quot; &quot;.\/usr\/local\/nginx\/scgi_temp&quot;   chown &quot;http:http&quot; &quot;.\/usr\/local\/nginx\/uwsgi_temp&quot;   chown &quot;http:http&quot; &quot;.\/usr\/local\/nginx\/fastcgi_temp&quot;    setcap &quot;cap_net_bind_service=+ep&quot; &quot;.\/usr\/local\/nginx\/sbin\/nginx&quot; }<\/code><\/pre>\n<p><code>EOF<\/code><\/p>\n<h2>\u0421\u0431\u043e\u0440\u043a\u0430<\/h2>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435, \u0432 \u043e\u0434\u0438\u043d \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b. \u0414\u043e\u0431\u0430\u0432\u0438\u0432\u2026<\/p>\n<p>  <code>user@linux:~$ cat &lt;&lt; EOF &gt;&gt; ~\/chroot-nginx.sh<\/code>  <\/p>\n<pre><code class=\"bash\">case &quot;${UID}&quot; in   &quot;0&quot;)     as_root &quot;$@&quot;     ;;   *)     main &quot;$@&quot;     ;; esac<\/code><\/pre>\n<p><code>EOF<\/code><\/p>\n<p>  \u0421\u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u0432 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e \u043a\u0443\u0441\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 \u0444\u0430\u0439\u043b, \u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u043c.<\/p>\n<p>  <code>user@linux:~$ chmod +x ~\/chroot-nginx.sh<\/code><\/p>\n<p>  \u0421 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0441\u0431\u043e\u0440\u043a\u0443 nginx \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e http.<\/p>\n<p>  <code>user@linux:~$ ~\/chroot-nginx.sh \/home\/user\/http<\/code><\/p>\n<p>  \u0417\u0430\u0439\u0434\u0435\u043c \u043f\u043e\u0434 \u0440\u0443\u0442\u043e\u043c \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0434\u043e\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 chroot-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <code>user@linux:~$ su --login<\/code><br \/>  <code>root@linux:~# \/home\/user\/chroot-nginx.sh \/home\/user\/http<\/code><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c \ud83d\ude42 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c nginx, \u0431\u0435\u0437 root!<\/p>\n<p>  <code>root@linux:~# \/usr\/bin\/chroot --userspec=http:http \/home\/user\/http \/usr\/local\/nginx\/sbin\/nginx -g &quot;daemon on; master_process on;&quot;<\/code><\/p>\n<p>  <a href=\"http:\/\/img827.imageshack.us\/img827\/6852\/201302202103311024x768s.png\"><img decoding=\"async\" src=\"http:\/\/imageshack.us\/scaled\/thumb\/827\/201302202103311024x768s.png\" alt=\"image\"\/><\/a><\/p>\n<p>  \u041d\u0430 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0423\u041c\u0412\u0420. \ud83d\ude42    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/170115\/\"> http:\/\/habrahabr.ru\/post\/170115\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 <a href=\"http:\/\/habrahabr.ru\/qa\/34889\/\">\u0441\u0432\u043e\u0435\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430<\/a> \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438, \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044f\u0442\u044c \u00ab\u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432\u00bb \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0438\u0445 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0436\u0435 \u043b\u043e\u043a\u0430\u043b\u0445\u043e\u0441\u0442 \u043e\u0442 \u0432\u0437\u043b\u043e\u043c\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b nginx \u0432 chroot&#8217;\u0435 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0441\u043a\u0440\u0438\u043f\u0442, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u0438\u044e\u0449\u0438\u0439 \u0441\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0432\u0437\u043b\u0430\u043c\u044b\u0432\u0430\u044e\u0442 \u0432\u0430\u0448 \u0441\u0435\u0440\u0432\u0435\u0440, \u0445\u0430\u0446\u043a\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u00abroot\u00bb, \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u0440\u043e\u043c\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e. \ud83d\ude42  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-170115","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/170115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=170115"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/170115\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=170115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=170115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=170115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}