Another Nginx module i’ve tested today, nginx-nonewlines , basically, this module same as Evan Miller’s nginx mod_strip module , Evan Miller’s mod_strip module removes unnecessary whitespace (spaces, tabs, and newlines) from HTML documents and automatically leaves comments as well as <pre></pre> tags untouched. while using using nginx-nonewlines we should define <!–SC_OFF–> and <!–SC_ON–> within the html code area that we’re intend to leaves them intact.
Here’s quick and dirty compiling nginx-nonewlines module
- download the module
https://github.com/vedang/nginx-nonewlines/archives/master
- add this line to ./configure step, compile and install
# ./configure \ .... .... --add-module=/path/to/vedang-nginx-nonewlines-ba02b59 .... .... # make && make install
add folowwing directive to nginx’s config.
server { gzip on; no_newlines on; listen 80; server_name www.example.com; access_log /var/log/nginx/nginx-test-access.log main; location / { root /home/user/public_html; index index.html index.htm; } }
example source html code before adding no_newlines directive.
<html> <head><title>The quick brown fox jumps over the lazy dog</title></head> <body> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> The quick brown fox jumps over the lazy dog<br> <pre> The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog </pre> </body> </html>
example after no_newlines added (with <!–SC_OFF–> and <!–SC_ON–> surrounding <pre></pre> tag)
<!--SC_OFF--> <pre> The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog </pre> <!--SC_ON-->
Output:
<html><head><title>The quick brown fox jumps over the lazy dog</title></head><body>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br>The quick brown fox jumps over the lazy dog<br> <pre> The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog </pre> </body></html>
So far so good, but there is one bug here. if i turn off gzip to off, it throws error like this:
ERR_INVALID_CHUNKED_ENCODING
Well, that’s it for now.
Hi!
I get this error when compiling:
‘, needed by `objs/nginx’. Stop.et `objs/addon/vedang-nginx-nonewlines-82aeeba/ngx_http_no_newlines_module.o
make[1]: Leaving directory `/root/nginx-1.1.10′
make: *** [build] Error 2
Do you have any idea what that could be caused by?
are there any errors before that? looks like the errors is incomplete..