Install SSL certificate for Nginx

Recently I bought an SSL certificate for this blog from MegaSSLStore. My website is hosted on a FreeBSD machine and served by Nginx web server. In order to install the certificate on this machine, I downloaded from MegaSSLStore the certificate and CSR+private key and I copied them on my server in /usr/local/etc/nginx/ssl

# scp -P22 * root@razvantudorica.com:/usr/local/etc/nginx/ssl

root@RTU001 /usr/local/etc/nginx/ssl # ls -lh
total 32
-r-------- 1 root wheel 5.5K Dec 14 11:39 razvantudorica.com.ca-bundle
-r-------- 1 root wheel 1.9K Dec 14 11:39 razvantudorica.com.crt
-r-------- 1 root wheel 1.1K Dec 14 11:39 razvantudorica.com.csr
-r-------- 1 root wheel 1.7K Dec 14 11:39 razvantudorica.com.key

Because I have an .crt certificate and also a ca-bundle I need to combine these two files in one certificate:

cd /usr/local/etc/nginx/ssl
cat razvantudorica.com.crt razvantudorica.com.ca-bundle > razvantudorica.com-bundle.crt

After this, I changed the nginx website configuration file, in order to redirect all the traffic that is coming on http (port 80) on https (port 443).

Continue reading Install SSL certificate for Nginx

Monitor an error log with python and RabbitMQ

Nowadays there are many professional solutions to monitor your application for the errors. Some web frameworks have even build-in tools or support plugins to catch the programming exceptions and act accordingly.

Anyway, I wanted just to build a simple proof of concept how to monitor the web server error file and, when an event occurs and the file is changed, the monitoring script should send out an email. To monitor the log file I used pyinotify python module. This is an implementation on top of inotify, offering an easy interface to interact with the changes of the filesystem.

Continue reading Monitor an error log with python and RabbitMQ

Switch between branches using Nginx

For some of my projects, most of the time I use two branches: master and dev and I work mostly in dev. If I need to send the url to some clients with some dev/beta features I should create another (sub)domain like dev.myproject.com and sometimes, if I forget to change some configurations about the domain name (specially with some “very intelligent” CMSes that keeps the configuration in the database) I will get an email back saying “the new feature is not working” 🙂

Continue reading Switch between branches using Nginx

How to use python sched in a daemon process

Let’s assume we want to download a file (or to do some tasks) to every 5 seconds, but the condition is to not do the same task twice or more times at the same moment, even if takes more than 5 seconds. For example, we have a to download a file and this will take 8 seconds. Also, if takes more than 5 seconds, it should not wait until the next iteration, to start again (3 seconds more), but will start the download immediately.

So, the traditional cronjob/lock file combination was not suitable for my case.

Continue reading How to use python sched in a daemon process