Friday, July 20, 2012

ANT build: "warning: unmappable character for encoding UTF-8"

When you have java source files with iso-8859-1 encoding, you will get "warning: unmappable character for encoding UTF-8". This can be avoided by below options.

1. Add -Dfile.encoding=iso-8859-1 to ANT_OPTS environment variable or providing this as command line parameter as ant -Dfile.encoding=iso-8859-1
2. Javac task has encoding attribute, through which we can specify particular encoding.
<javac srcdir="${src.dir}" destdir="${classes.dir}" encoding="iso-8859-1" />

Wednesday, July 18, 2012

Configuring smart host setup with SMTP authentication for Sendmail

This post describes step by step to setup your Sendmail to send email through desired SMTP provider such as your ISP or gmail, etc

Before Sendmail 8.12

1.  Add the below entries in /etc/mail/sendmail.mc file (check if apropriate settings doesn't already exists):
define(`SMART_HOST',`smtp.my.isp.com')
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl

 2. Setup your authorization information by entering below information in /etc/mail/client-info file:

AuthInfo:smtp.my.isp.com "U:smmsp" "I:user" "P:password" "M:PLAIN"

Use your ISP or mail server, Leave "U:smmsp" as is, and update your username and password.

3. Update the configuration files

# cd /etc/mail 
# m4 sendmail.mc >sendmail.cf 
# makemap hash client-info < client-info

You will require sendmail-cf package to update the sendmail.cf file using m4 as above.

4. Set permissions:

# chmod 644 client-info
# chmod 640 client-info.db

5. Reload or restart Sendmail
# /etc/init.d/sendmail restart

Sendmail 8.12 and above:
As of sendmail 8.12 and above, authinfo is built into sendmail.cf so all you have to do is add your "AuthInfo" statement to /etc/mail/access.

1.  Add the below entries in /etc/mail/sendmail.mc file (check if apropriate settings doesn't already exists):
 define(`SMART_HOST',`smtp.my.isp.com')
  2. Setup your authorization information by entering below information in /etc/mail/access file:

AuthInfo:smtp.my.isp.com "U:smmsp" "I:user" "P:password" "M:PLAIN"

Use your ISP or mail server, Leave "U:smmsp" as is, and update your username and password.

3. Update the configuration files

# cd /etc/mail 
# m4 sendmail.mc >sendmail.cf 
# makemap hash access < access


4. Set permissions:

# chmod 644 access
# chmod 640 access.db
 5. Reload or restart Sendmail
# /etc/init.d/sendmail restart

Wednesday, July 11, 2012

HTTP to HTTPS Redirect with Amazon ELB and Apache

Recently, I had to force https traffic in one of the project for the production server setup in AWS. My configuration looks as below.

I have ELB configured to load balance end users requests to the Apache on the backend. The ELB listeners are configured as below 

HTTP Port 80 -> 80
HTTPS Port 443 -> 443 with backend authentication disabled.

Both the listeners are configured with ELB cookie stickiness policy.

With HTTP/HTTPS termination, ELB sets a X-Forwarded-Proto header that allows you to tell which protocol the client used to connect to your load balancer. We can use this header with mod_rewrite rule to force https traffic. Here's the configuration changes done 
 <VirtualHost *:80>
  ...
  RewriteEngine On
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
  ...
 </VirtualHost>
(this assumes your health status is on /status, which doesn't require https)

Tuesday, July 10, 2012

Installing developer tools on Ubuntu

Most server distributions do not have the developer tools installed by default. The developer tools such as gcc c/c++ compilers, make and linkers are required to install any packages such are nodejs, memcache, etc from the source. Fortunately all the developer tools, including gcc c/c++ compilers, make and others can be installed easily using a single apt-get command. There is a convenient meta-package called 'build-essential' that will install all the developer tools with just one command.

Run the following command:

sudo apt-get update && sudo apt-get install build-essential


You will see the output asking for confirmation for a list of packages to be installed/updated. Please enter 'Y' for yes when prompted. All the required packages will be downloaded from the repository and installed.