{"id":11394,"date":"2016-10-25T21:53:28","date_gmt":"2016-10-25T12:53:28","guid":{"rendered":"https:\/\/jirak.net\/wp\/compiling-dynamic-modules-for-nginx-plus\/"},"modified":"2016-10-25T22:34:40","modified_gmt":"2016-10-25T13:34:40","slug":"compiling-dynamic-modules-for-nginx-plus","status":"publish","type":"post","link":"https:\/\/jirak.net\/wp\/compiling-dynamic-modules-for-nginx-plus\/","title":{"rendered":"Compiling Dynamic Modules for NGINX Plus"},"content":{"rendered":"<p>Compiling Dynamic Modules for NGINX Plus<\/p>\n<p><a href=\"https:\/\/www.nginx.com\/nginx-plus-r11-released?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">NGINX&nbsp;Plus Release&nbsp;R11<\/a> introduces binary compatibility for dynamic modules. This article describes the build process, explaining how to compile third&#8209;party NGINX modules so that they can be used in the NGINX&nbsp;Plus product.<\/p>\n<h2>NGINX Modules Overview<\/h2>\n<p>NGINX modules are written in C and conform to the API described in <a href=\"https:\/\/www.nginx.com\/resources\/wiki\/extending\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">Extending NGINX<\/a> on the NGINX&nbsp;Wiki. There is a <a href=\"https:\/\/www.nginx.com\/resources\/wiki\/modules\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">large ecosystem of third&#8209;party modules<\/a>, ranging from language interpreters to security solutions, and some of these are <a href=\"https:\/\/www.nginx.com\/products\/technical-specs\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog#dynamic-modules\">included and supported<\/a> in NGINX&nbsp;Plus.<\/p>\n<p>Other third&#8209;party modules, and modules that you have created yourself, need to be compiled independently and loaded into NGINX&nbsp;Plus at runtime. You can compile these modules for use with NGINX&nbsp;Plus by building them against the open source NGINX software as described below:<\/p>\n<ol>\n<li><a href=\"?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog#obtain-oss\">Obtain the matching open source NGINX release<\/a><\/li>\n<li><a href=\"?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog#obtain-module\">Obtain the module sources<\/a>, and update the config shell script if necessary to support the NGINX dynamic modules capability introduced in NGINX 1.9.11<\/li>\n<li><a href=\"?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog#build-module\">Build the dynamic module<\/a> against the open source NGINX release, with the <code>&#8209;&#8209;with&#8209;compat<\/code> argument to the <code>configure<\/code> command<\/li>\n<li><a href=\"?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog#load-module\">Load the resulting dynamic module<\/a> (the <strong>.so<\/strong> file) into NGINX&nbsp;Plus and use it as if it were a built&#8209;in module<\/li>\n<\/ol>\n<h2>Example: A Simple \u201cHello World\u201d Module<\/h2>\n<p>This example uses a simple <a target=\"_blank\" href=\"https:\/\/github.com\/perusio\/nginx-hello-world-module?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">Hello World module<\/a> to show how to update the source for a module and load it in NGINX&nbsp;Plus. The \u201cHello World\u201d module implements a simple directive (<code>hello_world<\/code>) that responds to requests with a simple message.<\/p>\n<h3 id=\"obtain-oss\">Step 1: Obtain the Open Source NGINX Release<\/h3>\n<p>Determine the open source NGINX version that corresponds to your NGINX&nbsp;Plus installation:<\/p>\n<pre><code class=\"terminal\">$ <strong>nginx -v<\/strong><br \/>\nnginx version: nginx\/1.11.5 (nginx-plus-r11)<\/pre>\n<p><\/code><\/p>\n<p>In this example, it\u2019s NGINX 1.11.5. Download the corresponding open source NGINX package from <a target=\"_blank\" href=\"http:\/\/nginx.org\/download?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">build repository<\/a> at <strong>nginx.org<\/strong>:<\/p>\n<pre><code class=\"terminal\">$ <strong>wget http:\/\/nginx.org\/download\/nginx-1.11.5.tar.gz<\/strong><br \/>\n$ <strong>tar -xzvf nginx-1.11.5.tar.gz<\/strong><\/pre>\n<p><\/code><\/p>\n<h3 id=\"obtain-module\">Step 2: Obtain the Module Sources<\/h3>\n<p>Obtain the source for the \u2018Hello World\u2019 NGINX module from <a target=\"_blank\" href=\"https:\/\/github.com\/perusio\/nginx-hello-world-module?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">GitHub<\/a>:<\/p>\n<pre><code class=\"terminal\">$ <strong>git clone https:\/\/github.com\/perusio\/nginx-hello-world-module.git<\/strong><\/pre>\n<p><\/code><\/p>\n<p>When dynamic modules were introduced, it was necessary to change the <a href=\"https:\/\/www.nginx.com\/resources\/wiki\/extending\/new_config\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">config shell file<\/a> that defines parameters for the module build process. It\u2019s straightforward to update old&#8209;style config shell files to support the new parameters, as documented on the <a href=\"https:\/\/www.nginx.com\/resources\/wiki\/extending\/converting\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">NGINX&nbsp;Wiki<\/a>.<\/p>\n<p>Modify the file <strong>nginx&#8209;hello&#8209;world&#8209;module\/config<\/strong> to contain the following:<\/p>\n<pre><code class=\"config\">ngx_addon_name=ngx_http_hello_world_module<\/p>\n<p>if test -n \"$ngx_module_link\"; then<br \/>\n    ngx_module_type=HTTP<br \/>\n    ngx_module_name=ngx_http_hello_world_module<br \/>\n    ngx_module_srcs=\"$ngx_addon_dir\/ngx_http_hello_world_module.c\"<\/p>\n<p>    . auto\/module<br \/>\nelse<br \/>\n    HTTP_MODULES=\"$HTTP_MODULES ngx_http_hello_world_module\"<br \/>\n    NGX_ADDON_SRCS=\"$NGX_ADDON_SRCS $ngx_addon_dir\/ngx_http_hello_world_module.c\"<br \/>\nfi<\/pre>\n<p><\/code><\/p>\n<h3 id=\"build-module\">Step 3: Compile the Dynamic Module<\/h3>\n<p>Compile the module by first running the <a target=\"_blank\" href=\"http:\/\/nginx.org\/en\/docs\/configure.html?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\"><code>configure<\/code><\/a> script with the new <code>&#8209;&#8209;with&#8209;compat<\/code> argument, which creates a standard build environment supported by both open source NGINX and NGINX&nbsp;Plus. Then run <code>make<\/code>&ensp;<code>modules<\/code> to build the module:<\/p>\n<pre><code class=\"terminal\">$ <strong>cd nginx-1.11.5\/<\/strong><br \/>\n$ <strong>.\/configure --with-compat --add-dynamic-module=..\/nginx-hello-world-module<\/strong><br \/>\n$ <strong>make modules<\/strong><\/pre>\n<p><\/code><\/p>\n<p>Copy the module library (<strong>.so<\/strong> file) to <strong>\/etc\/nginx\/modules<\/strong>:<\/p>\n<pre><code class=\"terminal\">$ <strong>sudo cp objs\/ngx_http_hello_world_module.so \/etc\/nginx\/modules\/<\/strong><\/pre>\n<p><\/code><\/p>\n<h3 id=\"load-module\">Step 4: Load and Use the Module<\/h3>\n<p>To load the module into NGINX&nbsp;Plus, add the <a target=\"_blank\" href=\"http:\/\/nginx.org\/en\/docs\/ngx_core_module.html?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog#load_module\"><code>load_module<\/code><\/a> directive in the top&#8209;level (main) context of your <strong>nginx.conf<\/strong> configuration file (not within the <code>http<\/code> or <code>stream<\/code> context):<\/p>\n<pre><code class=\"config\">load_module modules\/ngx_http_hello_world_module.so;<\/pre>\n<p><\/code><\/p>\n<p>The module provides a <code>hello_world<\/code> directive that returns the response \u2018hello world\u2019 from a <code>location<\/code> block:<\/p>\n<pre><code class=\"config\">server {<br \/>\n    listen 80;<\/p>\n<p>    location \/ {<br \/>\n         hello_world;<br \/>\n    }<br \/>\n}<\/pre>\n<p><\/code><\/p>\n<p>Reload your NGINX&nbsp;Plus configuration and test it with a simple request:<\/p>\n<pre><code class=\"terminal\">$ <strong>nginx -s reload<\/strong><br \/>\n$ <strong>curl http:\/\/localhost\/<\/strong><br \/>\nhello world<\/pre>\n<p><\/code><\/p>\n<h2>Example 2: The NAXSI Web Application Firewall<\/h2>\n<p><a target=\"_blank\" href=\"https:\/\/github.com\/nbs-system\/naxsi?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">NAXSI<\/a> is an easy&#8209;to&#8209;use, high&#8209;performance web application firewall (WAF) that uses heuristics and a scoring system to identify suspicious requests such as XSS and SQL Injection attacks.<\/p>\n<p>The NAXSI source has been updated to comply with the new format for the configuration shell file, so building a dynamic module for NGINX&nbsp;Plus is straightforward. The process is based on the <a target=\"_blank\" href=\"https:\/\/github.com\/nbs-system\/naxsi\/wiki\/naxsi-compil?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">NAXSI installation instructions<\/a>:<\/p>\n<pre><code class=\"terminal\">$ <strong>git clone https:\/\/github.com\/nbs-system\/naxsi.git<\/strong><br \/>\n$ <strong>cd nginx-1.11.5\/<\/strong><br \/>\n$ <strong>.\/configure --with-compat --add-dynamic-module=..\/naxsi\/naxsi_src<\/strong><br \/>\n$ <strong>make modules<\/strong><br \/>\n$ <strong>sudo cp objs\/ngx_http_naxsi_module.so \/etc\/nginx\/modules<\/strong><\/pre>\n<p><\/code><\/p>\n<h3>Using the NAXSI Module with NGINX Plus<\/h3>\n<p>Load the module into the NGINX&nbsp;Plus core by adding the <code>load_module<\/code> directive to the main context in your <strong>nginx.conf<\/strong> file:<\/p>\n<pre><code class=\"config\">load_module modules\/ngx_http_naxsi_module.so;<\/pre>\n<p><\/code><\/p>\n<p>NAXSI configuration is described in detail in the <a target=\"_blank\" href=\"https:\/\/github.com\/nbs-system\/naxsi\/wiki?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">project documentation<\/a>. The following NGINX configuration illustrates the module in action:<\/p>\n<pre><code class=\"config\"># Edit this 'include' directive to point to your naxsi_core.rules file<br \/>\ninclude \/home\/owen\/src\/naxsi\/naxsi_config\/naxsi_core.rules;<\/p>\n<p>server {<br \/>\n    listen 80;<\/p>\n<p>    location \/ {<br \/>\n        root \/usr\/share\/nginx\/html;<\/p>\n<p>        # Enable NAXSI<br \/>\n        SecRulesEnabled;<\/p>\n<p>        # Define where blocked requests go<br \/>\n        DeniedUrl \"\/50x.html\";<\/p>\n<p>        # CheckRules, determining when NAXSI needs to take action<br \/>\n        CheckRule \"$SQL &gt;= 8\" BLOCK;<br \/>\n        CheckRule \"$RFI &gt;= 8\" BLOCK;<br \/>\n        CheckRule \"$TRAVERSAL &gt;= 4\" BLOCK;<br \/>\n        CheckRule \"$EVADE &gt;= 4\" BLOCK;<br \/>\n        CheckRule \"$XSS &gt;= 8\" BLOCK;<\/p>\n<p>        # Don\u2019t forget the error_log, where blocked requests are logged<br \/>\n        error_log \/tmp\/naxsi.log;<br \/>\n    }<\/p>\n<p>    error_page   500 502 503 504  \/50x.html;<br \/>\n}<\/pre>\n<p><\/code><\/p>\n<p>You can verify the correct operation of NAXSI with a pair of simple HTTP requests:<\/p>\n<ul>\n<li><code>curl<\/code>&ensp;<code>http:\/\/localhost\/<\/code> returns the standard NGINX&nbsp;Plus index page stored in <strong>\/usr\/share\/nginx\/html<\/strong>.<\/li>\n<li><code>curl<\/code>&ensp;<code>\"http:\/\/localhost\/?a=&lt;&gt;\"<\/code> triggers NAXSI\u2019s XSS detection and blocks the request, returning the standard <strong>50x.html<\/strong> error page from <strong>\/usr\/share\/nginx\/html<\/strong>. It also logs a message to the <strong>error_log<\/strong>.<\/li>\n<\/ul>\n<p>For production deployments, you can also <a target=\"_blank\" href=\"https:\/\/github.com\/nbs-system\/naxsi\/tags?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">download signed NAXSI releases<\/a> at <strong>https:\/\/github.com\/nbs-system\/naxsi\/tags<\/strong><\/a> and compile them in a similar fashion.<\/p>\n<h2>How We Support Dynamic Modules<\/h2>\n<p><a href=\"https:\/\/www.nginx.com\/products\/technical-specs\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">NGINX&nbsp;Plus ships with a number of dynamic modules<\/a> that you can install directly from our modules repository. There are two types:<\/p>\n<ul>\n<li><strong>NGINX&#8209;Authored Modules<\/strong> are written and maintained by the NGINX, Inc. engineering team. We don&#8217;t include them in NGINX&nbsp;Plus for technical reasons (they have additional dependencies) or because they are in a preview state. Preview modules&nbsp;&ndash; currently, nginScript and ModSecurity&nbsp;&ndash; are in active development and should only be deployed with great care. The other modules of this type&nbsp;&ndash; currently <a target=\"_blank\" href=\"http:\/\/nginx.org\/en\/docs\/http\/ngx_http_geoip_module.html?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">GeoIP<\/a>, <a target=\"_blank\" href=\"http:\/\/nginx.org\/en\/docs\/http\/ngx_http_image_filter_module.html?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">Image&#8209;Filter<\/a>, <a target=\"_blank\" href=\"http:\/\/nginx.org\/en\/docs\/http\/ngx_http_perl_module.html?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">Perl<\/a>, and <a target=\"_blank\" href=\"http:\/\/nginx.org\/en\/docs\/http\/ngx_http_xslt_module.html?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">XSLT<\/a>&nbsp;&ndash; are fully supported by NGINX,&nbsp;Inc.<\/li>\n<li><strong>NGINX&#8209;Certified Community Modules<\/strong> are popular third&#8209;party modules that NGINX tests and distributes, and for which we provide installation and basic configuration support. We warrant that these modules do not interfere with the correct operation of NGINX&nbsp;Plus, and we update them as necessary at each NGINX&nbsp;Plus release or when there is a security release.<\/li>\n<\/ul>\n<p>Modules that you compile yourself (community modules, modules provided by third&#8209;party partners, and custom modules) are not tested or supported by NGINX. If you seek technical support for a problem, the NGINX technical support team may ask you to remove an unsupported module and reproduce the fault as part of our technical support process, so that they can verify whether or not the fault is caused by the unsupported module.<\/p>\n<h2>Summary<\/h2>\n<p>The dynamic modules build process for NGINX&nbsp;Plus allows you to take advantage of the broad ecosystem of open source NGINX modules, running them on the rich and fully supported NGINX&nbsp;Plus core.<\/p>\n<p>If you are currently using open source NGINX with third&#8209;party extensions, these extensions can most likely be compiled and loaded into NGINX&nbsp;Plus.<\/p>\n<p>If you develop commercial or community modules, the new build process means your users can deploy your modules with NGINX&nbsp;Plus.<\/p>\n<p>If you need assistance in developing a module or updating it to support the newer config shell file format, please check out the following resources:<\/p>\n<ul>\n<li><a target=\"_blank\" href=\"http:\/\/www.evanmiller.org\/nginx-modules-guide.html?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">Emiller\u2019s Guide to NGINX Module Development<\/a> by Evan&nbsp;Miller<\/li>\n<li><a href=\"https:\/\/www.nginx.com\/blog\/dynamic-modules-development\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">Dynamic Modules Development<\/a> for NGINX by Ruslan&nbsp;Ermilov<\/li>\n<li><a href=\"https:\/\/www.nginx.com\/resources\/wiki\/extending\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">Extending NGINX<\/a> on the NGINX&nbsp;Wiki<\/li>\n<li><a href=\"https:\/\/www.nginx.com\/resources\/wiki\/extending\/converting\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">Converting Static Modules to Dynamic Modules<\/a> on the NGINX&nbsp;Wiki<\/li>\n<li><a target=\"_blank\" href=\"https:\/\/www.airpair.com\/nginx\/extending-nginx-tutorial?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">NGINX Tutorial: Developing Modules<\/a> by Aaron&nbsp;Bedra<\/li>\n<\/ul>\n<p>The <a target=\"_blank\" href=\"http:\/\/mailman.nginx.org\/mailman\/listinfo?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">NGINX Developers mailing list<\/a> is the go&#8209;to place for community assistance, and our <a href=\"https:\/\/www.nginx.com\/services\/?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog\">Professional Services team<\/a> will be happy to assist.<\/p>\n<p>To try dynamic modules with NGINX&nbsp;Plus yourself, start a <span><a href=\"?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog#free-trial\">free 30&#8209;day trial<\/a><\/span> today or <a href=\"?utm_source=compiling-dynamic-modules-nginx-plus&amp;utm_medium=blog#contact-us\">contact&nbsp;us<\/a> for a live demo.<\/p>\n<p>The post <a rel=\"nofollow\" href=\"https:\/\/www.nginx.com\/blog\/compiling-dynamic-modules-nginx-plus\/\">Compiling Dynamic Modules for NGINX Plus<\/a> appeared first on <a rel=\"nofollow\" href=\"https:\/\/www.nginx.com\">NGINX<\/a>.<\/p>\n<p>Source: <a href=\"https:\/\/www.nginx.com\/blog\/compiling-dynamic-modules-nginx-plus\/\" target=\"_blank\">Compiling Dynamic Modules for NGINX Plus<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Compiling Dynamic Modules for NGINX Plus NGINX&nbsp;Plus Release&nbsp;R11 introduces binary compatibility for dynamic modules. This article describes the build process, explaining how to compile third&#8209;party NGINX modules so that they can be used in the NGINX&nbsp;Plus product. NGINX Modules Overview NGINX modules are written in C and conform to the API described in Extending NGINX on the NGINX&nbsp;Wiki. There is a large ecosystem of third&#8209;party modules, ranging from language interpreters to security solutions, and some of these are included and supported in NGINX&nbsp;Plus. Other third&#8209;party modules, and modules that you have created yourself, need to be compiled independently and loaded into NGINX&nbsp;Plus at runtime. You can compile these modules for use with NGINX&nbsp;Plus by building them against the open source NGINX software as described below: Obtain the matching open source NGINX release Obtain the module sources, and update the config <a class=\"mh-excerpt-more\" href=\"https:\/\/jirak.net\/wp\/compiling-dynamic-modules-for-nginx-plus\/\" title=\"Compiling Dynamic Modules for NGINX Plus\">[ more&#8230; ]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[652],"class_list":["post-11394","post","type-post","status-publish","format-standard","hentry","category-news","tag-nginx"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/11394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/comments?post=11394"}],"version-history":[{"count":1,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/11394\/revisions"}],"predecessor-version":[{"id":11395,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/11394\/revisions\/11395"}],"wp:attachment":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/media?parent=11394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/categories?post=11394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/tags?post=11394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}