Linux/Unix

You are currently browsing the archive for the Linux/Unix category.

If you need a static version of your dynamic web application maybe you may interested to configure Nginx as reverse proxy cache so it can cache also dynamic contents (pages with ? in the URI).

Well, if this is your scenario, let’s go to configure Nginx.

Requirements
- Nginx up, running and listening on 80 port
- A web server, like Apache, listening on 8080 port

server {
listen       80;
server_name  www.example.com;

access_log  /var/log/nginx/host.access.log  main;
set $prefix  prefix_;

# proxy module defaults
proxy_store_access   user:rw  group:rw  all:r;
proxy_set_header  X-Real-IP  $remote_addr;
proxy_set_header  Host       $host;

# Main location
location / {

root /tmp/nginx/;
index index.html index.htm index.php index.php.html index.php.html;

# Use this if you don't cache a context (dont_cache_path) , send all requests through the proxy
location ~ ^/dont_cache_path {
  proxy_pass http://localhost:8080;
}

# if the request uri was a directory, store the index page name
if ($request_uri ~ /$) {
  set $store_extra ${request_uri}index;
}

# set the location the proxy will store the data to. Add the index page
# name if the uri was a directory (nginx can't normally store these)
proxy_store /tmp/nginx/${prefix}${query_string}${store_extra}.html;

# go through the proxy if there is no cache
if (!-f /tmp/nginx/${prefix}${query_string}${store_extra}.html) {
  proxy_pass http://localhost:8080;
}

# workaround. headers module doesn't take into account proxy response
# headers. It overwrites the proxy Cache-Control header, causing
# private/no-cache/no-store to be wiped, so only set if not using proxy
if (-f /tmp/nginx/${request_uri}${store_extra}.html) {
  expires 0;
}

# handle static files directly. Set their expiry time to max, so they'll
# always use the browser cache after first request
location ~* (css|js|png|jpe?g|gif|ico|swf)$ {
  root /var/www/html/;
  expires max;
}
error_page 404 = /${prefix}${query_string}${store_extra}.html;
}
}

Restart Nginx and enjoy with your static web site :-)

Reference Links:
- Nginx wiki
- how to use nginx to create static files from dynamic content
- Page-level caching with Nginx

Tags: , , , ,

The first beta version of Minerva (Ldap Password Changer) at version 0.5 has been released!

Minerva is a very little and simple PHP application with only one scope: permit at your openldap accounts to simply change its password without use other application (such as a webmail) that you can have or not.

Download it and tell us what you think about it!

Tags: , , , , ,

~# mkdir ~/tmp && cd ~/tmp
~# apt-get install dpkg-dev
~# apt-get source lighttpd
~# apt-get build-dep lighttpd
~# wget http://www.linux.com.cn/modcache/lighttpd-1.4.19.modcache.v.1.6.0.patch
~# cd lighttpd-1.4.19
~# patch -p0 < ../lighttpd-1.4.19.modcache.v.1.6.0.patch
~# echo debian/tmp/usr/lib/lighttpd/mod_cache.so > debian/lighttpd.install
~# dpkg-buildpackage  -uc -b
~# ls -l ../*.deb

Install the debian packages with dpkg and enjoy :-)

Reference Links:
- APT HOWTO – Working with source packages

Tags: , ,

~ $ cat example.txt
first line
second line
third line
another line

~ $ sed -n ‘/second/{n;p;}’ < example.txt
third line

~ $ sed -n ‘/second/{n;p;n;p;}’ < example.txt
third line
another line

Tags: ,

Install the ThinkFinger utilities and the relative PAM module:

~$ sudo apt-get install thinkfinger-tools libpam-thinkfinger

Acquire and test your fingerprint:

~$ sudo tf-tool --acquire
~$ sudo tf-tool --verify

Enable the PAM module:

~$ sudo /usr/lib/pam-thinkfinger/pam-thinkfinger-enable

Enjoy :-)

Resources
- wiki.ubuntu.com/ThinkFinger
- Bug #203973 in thinkfinger (Ubuntu)

Tags: ,

On Linux or Unix systems perform recursively a command on items might contain white space, quote marks, or backslashes can be a problem when using find | xargs combination.

To solve this you may use:

find -type d -print0 | xargs -0 <command>
find -type f -print0 | xargs -0 <command>

For example to fix recursively permission:

find -type d -print0 | xargs -0 chmod 755
find -type f -print0 | xargs -0 chmod 644

Tags: , ,