Blog About Contact

About the Author

Richard Nichols is an Australian software engineer with a passion for making things.

Follow him on twitter or subscribe by RSS or email.

Latest Post

Setting Up iptables for SSH/HTTP/HTTPS for new server install

Published Mon, 7 Apr 2014

Whenever I set up a new cloud server I have to lookup the commands to set up iptables correctly for the three sevices I almost always have switched on - SSH, HTTP, HTTPS. So here's a script for later reference!

iptables -F
iptables -I INPUT 1 -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -j DROP

Also a basic port 8080 reverse proxy setup for HTTP/HTTPS on nginx is handy too...

upstream app {
    #ip_hash;
    server localhost:8080;
}

server {
    listen 80;
    #rewrite ^(.*) https://$host$1 permanent;
    location / {
        proxy_pass http://app;
        proxy_redirect http:// https://;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
 }

server {

    listen 443;
    ssl on;
    ssl_certificate      /etc/nginx/myssl.crt;
    ssl_certificate_key  /etc/nginx/myssl.key;
    server_name  localhost;

    location / {
        proxy_pass http://app;
        proxy_redirect http:// https://;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

Older Posts

Creating and importing an external certificate to SQL Server Tue, 4 Mar 2014
This was kind of a pain to get working, so I'm logging the steps here. Certificates can be used in SQL Server to authenticate remote communication (e.g. for...
Getting nice font rendering in Netbeans 7 on Ubuntu 12.04 Wed, 21 Aug 2013
I recently switched to Ubuntu 12.04 for my work PC and I'm pretty happy with the results, except for terrible font rendering in Swing applications,...
Diagnosing transactions causing SQL Server's transaction log truncation to fail Mon, 12 Aug 2013
This is one of those "for my future reference" posts.To diagnose which transaction is causing SQL Server's transaction log truncation to fail, the...
Netbeans code template for SLF4J logging Mon, 29 Jul 2013
Here's a neat code template for Netbeans to add a static logger declaration to a class file. private static final Logger log ...
Can't change the font in Netbeans Output Window? Mon, 24 Jun 2013
I just spent 20 minutes trying to figure out why I couldn't change the font in Netbean's output window (which inexplicable uses Java's default system...
Dealing With Static Imports in Netbeans IDE Tue, 29 Jan 2013
Static imports can be quite a nice feature of the Java language for improving code readability and clarity, however they can be a bit of a pain to setup for use...
From Wordpress to Netty - Can you spot the difference? Thu, 24 Jan 2013
Here's the graph of landing page download times from pingdom - can you see spot where I dropped Wordpress Dreamhost and switched over to Netty Heroku?...
Clever way of waiting for a specified delay in a DOS / Windows batch file... Thu, 24 Jan 2013
Here's an interesting little tip. If you ever find yourself in the (unfortunate) position of having to write a DOS Windows batch file, and need to "wait for...