Installing additional modules to nginx
September 9, 2008
There are a wealth of plugins or modules you could add to your existing nginx installation. I have been testing one of them recently – the NGINX Upload module by Valery Kholodkov.The beauty of this module is to capture and parse the mime headers before sending the parsed information onto your application backend. Your application only has to handle the parsed information which is formatted in a POST request header. This is defintely a powerful module to have if your application deals with large volumes of user uploads.
If you have an existing macport installation of nginx, it is a very straightforward process. All we need to do is to replace the default binary installtion with a new compiled version that includes the plugin.
Firstly, you would need to grab the source of nginx which is located here. The most current version is 0.6.32. Extract the source to your local directory. Next, grab the module you want to include – in this example we are using the upload module as mentioned above.
Open up the command prompt and change into the nginx sources folder and issue the following commands:
cd nginx-0.6.32
sudo ./configure --add-module=../nginx_upload_module-2.0.6/ --prefix=/opt/local
--conf-path=etc/nginx/nginx.conf --sbin-path=sbin/ --with-http_ssl_module
The last command above uses the ‘add-module’ directive to include the module you want to add by specifying the path where it is located – in this case in the folder above the current directory called ‘nginx_upload_module’. The rest of the paramaters are pretty self-explanatory – it is pointing to where the default macport installtion of nginx resides namely /opt/local/sbin. The last parameter compiles the new nginx binary with ssl support.
If the command runs successfully, you should see the following on the screen:
Configuration summary
+ threads are not used
+ using system PCRE library
+ using system OpenSSL library
+ md5 library is not used
+ sha1 library is not used
+ using system zlib library
nginx path prefix: "/opt/local"
nginx binary file: "/opt/local/sbin/"
nginx configuration file: "/opt/local/etc/nginx/nginx.conf"
nginx pid file: "/opt/local/logs/nginx.pid"
nginx error log file: "/opt/local/logs/error.log"
nginx http access log file: "/opt/local/logs/access.log"
Lastly, run sudo make and sudo make install to complete the installation process. I restarted nginx using the following commands:
sudo launchctl stop org.macports.nginx
sudo launchctl start org.macports.nginx
You would need to refer to nginx.conf to alter the configuration option suited to the module you just added.
The entire process is semaless once you get your head round it but all it involves is just recompiling a new nginx binary to replace the one installed by macports. I think for those of you who have tried to compile new modules with apache would appreciate how easy it is to do the same thing with nginx – and I did not have to shut down the server for the entire process.