<code># Dockerfile to build openresety Installed Containers</code>
<code>FROM 192.168.1.67</code><code>/library/centos7</code><code>.4:v1</code>
<code>MAINTAINER xiayun <[email protected]></code>
<code>#Install necessary tools </code>
<code>RUN yum </code><code>install</code> <code>-y pcre-devel wget net-tools gcc zlib zlib-devel </code><code>make</code> <code>openssl-devel unzip python-devel</code>
<code>#download tar.gz</code>
<code>ADD https:</code><code>//openresty</code><code>.org</code><code>/download/openresty-1</code><code>.11.2.5.</code><code>tar</code><code>.gz .</code>
<code>ADD http:</code><code>//labs</code><code>.frickle.com</code><code>/files/ngx_cache_purge-2</code><code>.3.</code><code>tar</code><code>.gz .</code>
<code>ADD https:</code><code>//github</code><code>.com</code><code>/loveshell/ngx_lua_waf/archive/master</code><code>.zip .</code>
<code>#unzip </code>
<code>RUN </code><code>tar</code> <code>zxvf ngx_cache_purge-2.3.</code><code>tar</code><code>.gz </code>
<code>RUN </code><code>tar</code> <code>-zxvf openresty-1.11.2.5.</code><code>tar</code><code>.gz </code>
<code>RUN unzip master.zip</code>
<code>#install openresety</code>
<code>RUN </code><code>cd</code> <code>openresty-1.11.2.5 && .</code><code>/configure</code> <code>--prefix=</code><code>/usr/local/openresty</code> <code>--with-luajit --with-http_stub_status_module --with-pcre --with-pcre-jit --add-module=..</code><code>/ngx_cache_purge-2</code><code>.3/ && gmake && gmake </code><code>install</code>
<code>RUN </code><code>mkdir</code> <code>/usr/local/openresty/nginx/conf/waf/</code>
<code>RUN </code><code>mkdir</code> <code>/usr/local/openresty/nginx/logs/hack/</code>
<code>RUN </code><code>cp</code> <code>-r </code><code>/ngx_lua_waf-master/</code><code>* </code><code>/usr/local/openresty/nginx/conf/waf/</code>
<code>RUN </code><code>mv</code> <code>/usr/local/openresty/nginx/conf/nginx</code><code>.conf </code><code>/usr/local/openresty/nginx/conf/nginx</code><code>.conf.bak</code>
<code>RUN </code><code>mv</code> <code>/usr/local/openresty/nginx/conf/waf/config</code><code>.lua </code><code>/usr/local/openresty/nginx/conf/waf/config</code><code>.bak</code>
<code>COPY .nginx_conf </code><code>/usr/local/openresty/nginx/conf/nginx</code><code>.conf</code>
<code>COPY config.lua </code><code>/usr/local/openresty/nginx/conf/waf/config</code><code>.lua</code>
<code>#add user nginx </code>
<code>RUN </code><code>useradd</code> <code>-s </code><code>/sbin/nologin</code> <code>nginx</code>
<code>#chown nginx</code>
<code>RUN </code><code>chown</code> <code>-R nginx.nginx </code><code>/usr/local/openresty/</code>
<code>RUN </code><code>chown</code> <code>-R nginx.nginx </code><code>/ngx_cache_purge-2</code><code>.3</code>
<code>#Expose ports for 80</code>
<code>EXPOSE 80</code>
<code>#start openresty</code>
<code>CMD </code><code>/usr/local/openresty/nginx/sbin/nginx</code> <code>-g </code><code>"daemon off;"</code>
附1:.nginx_conf 与Dockerfile在同一路径
<code>user nginx nginx;</code>
<code>worker_processes 2;</code>
<code>error_log </code><code>/usr/local/openresty/nginx/logs/nginx_error</code><code>.log error;</code>
<code>pid </code><code>/usr/local/openresty/nginx/nginx</code><code>.pid;</code>
<code>worker_rlimit_nofile 65535;</code>
<code>events</code>
<code>{</code>
<code>use epoll;</code>
<code>worker_connections 65535;</code>
<code>}</code>
<code>http</code>
<code>lua_package_path </code><code>"/usr/local/openresty/nginx/conf/waf/?.lua"</code><code>;</code>
<code>lua_shared_dict limit 10m;</code>
<code>init_by_lua_file </code><code>/usr/local/openresty/nginx/conf/waf/init</code><code>.lua;</code>
<code>access_by_lua_file </code><code>/usr/local/openresty/nginx/conf/waf/waf</code><code>.lua;</code>
<code>include mime.types;</code>
<code>default_type application</code><code>/octet-stream</code><code>;</code>
<code>charset utf-8;</code>
<code>server_tokens off;</code>
<code>log_format main </code><code>'$host $status [$time_local] $upstream_addr $remote_addr - $remote_user [$time_local] $request_uri '</code>
<code>'"$http_referer" "$http_user_agent" "$http_x_forwarded_for" '</code>
<code>'$bytes_sent $request_time $sent_http_x_cache_hit "$upstream_cache_status"'</code><code>;</code>
<code>log_format log404 </code><code>'$status [$time_local] $remote_addr $host$request_uri $sent_http_location'</code><code>;</code>
<code>server_names_hash_bucket_size 128;</code>
<code>client_header_buffer_size 32k;</code>
<code>large_client_header_buffers 4 32k;</code>
<code>client_max_body_size 300m;</code>
<code>sendfile on;</code>
<code>fastcgi_intercept_errors on;</code>
<code>tcp_nopush on;</code>
<code>keepalive_timeout 20;</code>
<code>tcp_nodelay on;</code>
<code>client_body_timeout 10;</code>
<code>client_body_buffer_size 512k;</code>
<code>gzip</code> <code>on;</code>
<code>gzip_min_length 1k;</code>
<code>gzip_buffers 4 16k;</code>
<code>gzip_http_version 1.1;</code>
<code>gzip_comp_level 2;</code>
<code>gzip_types text</code><code>/plain</code> <code>application</code><code>/x-javascript</code> <code>text</code><code>/css</code> <code>application</code><code>/xml</code><code>;</code>
<code>gzip_vary on;</code>
<code>send_timeout 60;</code>
<code>open_file_cache max=200000 inactive=20s;</code>
<code>open_file_cache_valid 30s;</code>
<code>open_file_cache_min_uses 2;</code>
<code>open_file_cache_errors on;</code>
<code>ssi on;</code>
<code>ssi_silent_errors on;</code>
<code>ssi_types text</code><code>/shtml</code><code>;</code>
<code>server</code>
<code>listen 80;</code>
<code>server_name localhost;</code>
<code>index index.html index.htm index.shtml index.php;</code>
<code> </code><code>root </code><code>/usr/local/openresty/nginx/html</code><code>;</code>
<code> </code>
<code>if</code> <code>($http_user_agent ~* </code><code>"Baiduspider-render|qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot"</code><code>)</code>
<code>return</code> <code>403;</code>
<code>location ~ \.php$ {</code>
<code>include fastcgi_params;</code>
<code>fastcgi_pass unix:</code><code>/tmp/php-fcgi</code><code>.sock;</code>
<code>fastcgi_index index.php;</code>
<code>fastcgi_param SCRIPT_FILENAME </code><code>/usr/local/nginx/html</code><code>$fastcgi_script_name;</code>
附2:config.lua与Dockerfile同一路径
<code>RulePath = </code><code>"/usr/local/openresty/nginx/conf/waf/wafconf/"</code>
<code>attacklog = </code><code>"on"</code>
<code>logdir = </code><code>"/usr/local/openresty/nginx/logs/hack/"</code>
<code>UrlDeny=</code><code>"off"</code>
<code>Redirect=</code><code>"off"</code>
<code>CookieMatch=</code><code>"off"</code>
<code>postMatch=</code><code>"off"</code>
<code>whiteModule=</code><code>"off"</code>
<code>black_fileExt={</code><code>"php"</code><code>,</code><code>"jsp"</code><code>}</code>
<code>ipWhitelist={</code><code>"127.0.0.1"</code><code>,</code><code>"192.168.20.25"</code><code>}</code>
<code>ipBlocklist={}</code>
<code>CCDeny=</code><code>"off"</code>
<code>CCrate=</code><code>"100/60"</code>
<code>html=[[</code>
<code><html xmlns=</code><code>"http://www.w3.org/1999/xhtml"</code><code>><</code><code>head</code><code>></code>
<code><meta http-equiv=</code><code>"Content-Type"</code> <code>content=</code><code>"text/html; charset=utf-8"</code><code>></code>
<code><title>网站防火墙<</code><code>/title</code><code>></code>
<code><style></code>
<code>p {</code>
<code> </code><code>line-height:20px;</code>
<code>ul{ list-style-</code><code>type</code><code>:none;}</code>
<code>li{ list-style-</code><code>type</code><code>:none;}</code>
<code><</code><code>/style</code><code>></code>
<code><</code><code>/head</code><code>></code>
<code><body style=</code><code>" padding:0; margin:0; font:14px/1.5 Microsoft Yahei, 宋体,sans-serif; color:#555;"</code><code>></code>
<code> </code><code><div style=</code><code>"margin: 0 auto; width:1000px; padding-top:70px; overflow:hidden;"</code><code>></code>
<code> </code>
<code> </code><code><div style=</code><code>"width:600px; float:left;"</code><code>></code>
<code> </code><code><div style=</code><code>" height:40px; line-height:40px; color:#fff; font-size:16px; overflow:hidden; background:#6bb3f6; padding-left:20px;"</code><code>>网站防火墙 <</code><code>/div</code><code>></code>
<code> </code><code><div style=</code><code>"border:1px dashed #cdcece; border-top:none; font-size:14px; background:#fff; color:#555; line-height:24px; height:220px; padding:20px 20px 0 20px; overflow-y:auto;background:#f3f7f9;"</code><code>></code>
<code> </code><code><p style=</code><code>" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"</code><code>><span style=</code><code>" font-weight:600; color:#fc4f03;"</code><code>>您的请求带有不合法参数,已被网站管理员设置拦截!<</code><code>/span</code><code>><</code><code>/p</code><code>></code>
<code><p style=</code><code>" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"</code><code>>可能原因:您提交的内容包含危险的攻击请求<</code><code>/p</code><code>></code>
<code><p style=</code><code>" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:1; text-indent:0px;"</code><code>>如何解决:<</code><code>/p</code><code>></code>
<code><ul style=</code><code>"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"</code><code>><li style=</code><code>" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"</code><code>>1)检查提交内容;<</code><code>/li</code><code>></code>
<code><li style=</code><code>" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"</code><code>>2)如网站托管,请联系空间提供商;<</code><code>/li</code><code>></code>
<code><li style=</code><code>" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"</code><code>>3)普通网站访客,请联系网站管理员;<</code><code>/li</code><code>><</code><code>/ul</code><code>></code>
<code> </code><code><</code><code>/div</code><code>></code>
<code> </code><code><</code><code>/div</code><code>></code>
<code><</code><code>/div</code><code>></code>
<code><</code><code>/body</code><code>><</code><code>/html</code><code>></code>
<code>]]</code>
本文转自YU文武貝 51CTO博客,原文链接:http://blog.51cto.com/linuxerxy/2047812,如需转载请自行联系原作者