RSS

Apache and nginx on same server with multiple IP addresses

In order to get this to work, you need to specify the IP and port each should listen in the domain configuration file (and NOT in the global web-server config).

nginx configuration for a domain (/etc/nginx/sites-enabled/www.mydomain.com) contains:

listen 11.22.33.44:80;
server_name http://www.mydomain.com mydomain.com;

Apache configuration for another domain contains:

In this case, this was at the top of /etc/apache2/sites-enabled/myotherdomain.com

WIth this setup, each web server has its own IP to listen to and they both serve on port 80.

Advertisements
 
Leave a comment

Posted by on November 2, 2010 in Apache, Linux, nginx

 

Tags: ,

nginx config file which works great with Codeigniter 2.0

This config file works great on Ubuntu 10.04 LTS server with nginx 0.7.65. Other software includes php 5.3.2, Code Igniter 2.0. Performance-wise I was able to squeeze 12,000 requests per second on static files and ~250 req/s on dynamic PHP pages.

This is a copy-paste from Chris Gaunt’s github page with a change in server name.

server {
    listen 8080;
    server_name www.metak.com metak.com;
    access_log /home/metak/metak.com/logs/access.log;
    error_log /home/metak/metak.com/logs/error.log;
    root   /home/metak/metak.com/public_html;

    # If file is an asset, set expires and break
    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
        expires max;
        break;
    }

	# Serve the directory/file if it exists, else pass to CodeIgniter front controller
	location / {
		try_files $uri @codeigniter;
	}

	# Do not allow direct access to the CodeIgniter front controller
	location ~* ^/index.php {
		rewrite ^/index.php/?(.*)$ /$1 permanent;
	}

	# CodeIgniter Front Controller
	location @codeigniter {
		internal;
		root /home/metak/metak.com/public_html;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		include fastcgi_config;
		include fastcgi_params;
		fastcgi_param SCRIPT_FILENAME /home/metak/metak.com/public_html/index.php;
	}

	# If directly accessing a PHP file in the public dir other than index.php
	location ~* \.php$ {
		root /home/metak/metak.com/public_html;
		try_files $uri @codeigniter;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		include fastcgi_config;
		include fastcgi_params;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	}

}
 
2 Comments

Posted by on October 2, 2010 in Linux, nginx, Ubuntu

 

CodeIgniter 1.7.2 and SQLite 3

Nice little trick to get CI and sqlite3 to work together. Specify the database file location but prefix it with ‘sqlite:’.

$db['default']['database'] = 'sqlite:'.APPPATH.'data/dictionary.sqlite3';

Tip taken from:
http://blog.trevorbramble.com/past/2009/9/20/codeigniter_sqlite3/

 
Leave a comment

Posted by on January 13, 2010 in Uncategorized

 

Compare two directories

Great command for recursively comparing directories on Linux or Mac.

diff -rq dirA dirB

It sorts all files by name and than reports if a file exists in one and not the other. It also reports if files of same name exist in both directories but differ in content.

 
Leave a comment

Posted by on January 12, 2010 in Linux, Mac OS

 

Subversion pre-commit hook for detection of byte-order marks (BOMs)

Byte-order marks can mess up your code badly. Some of my CodeIgniter PHP code was receiving “headers already sent”, thanks to BOM’s alone. So, our goal is to reject a commit that contains one or more PHP files with BOMs. You can easily change the script to filter other files as well. The script is known to work on Dreamhost.

Enough of talking, here is the pre-commit hook, a bash script, you were desperately searching the Internet for:

#!/bin/bash

REPOS="$1"
TXN="$2"

PHP="/usr/local/bin/php"
SVNLOOK="/usr/bin/svnlook"
AWK="/usr/bin/awk"
GREP="/bin/egrep"
SED="/bin/sed"

CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS" | $GREP "^[U|A]" | $AWK '{print $2}' | $GREP \.php$`

REGEX=$'\xEF\xBB\xBF'
GREP2="grep -l $REGEX"

for FILE in $CHANGED
do
    MESSAGE=`$SVNLOOK cat -t "$TXN" "$REPOS" "$FILE" | $GREP2`
    if [ $? -eq 0 ]
    then
        echo 1>&2
        echo "***********************************" 1>&2
        echo "Byte order mark error in: $FILE:" 1>&2
        #echo `echo "$MESSAGE" | $SED "s| -| $FILE|g"` 1>&2
        echo "***********************************" 1>&2
        exit 1
    fi
done

 
1 Comment

Posted by on September 30, 2009 in Linux, Subversion

 

Tags: , , , ,

Make MAMP PRO not ask about passwords on service restart

Change your default MAMP password from ‘root’ to something more useful:
/Applications/MAMP/bin/mysql4/bin/mysqladmin -u root -p password newpassword

Edit the following files:

  • /Applications/MAMP/bin/phpMyAdmin-X.X.X/config.inc.php

    $cfg['Servers'][$i]['password'] = 'newpassword'; // change root to your new password

  • /Applications/MAMP/bin/mamp/index.php

    $link = @mysql_connect(’:/Applications/MAMP/tmp/mysql/mysql.sock’, ‘root’, ‘newpassword‘);

  • /Applications/MAMP/bin/stopMysql.sh

    # /bin/sh
    /Applications/MAMP/bin/mysql4/bin/mysqladmin -u root -pnewpassword –socket=/Applications/MAMP/tmp/mysql/mysql.sock shutdown

Tip taken from this site.

 
Leave a comment

Posted by on March 20, 2009 in Mac OS, Uncategorized

 

Tags: , , , ,

Rotating Apache logs with logrotate

It’s pretty easy to set this up on Linux as most distros come with rotatelog functionality.

All I had to do was to create a file /etc/logrotate.d/apache2 with this content:

/usr/local/apache/domlogs/www3.serbiancafe.com.short {
daily
missingok
rotate 5
ifempty
copytruncate
olddir /usr/local/apache/domlogs/oldlogs
}

/usr/local/apache/logs/*_log {
rotate 3
size 100M
copytruncate
}

If plain English:
First log is rotated on a daily basis regardless if the log is there or empty. Last 5 logs are kept in “olddir” directory. And, you don’t have to restart Apache when you use copytruncate directive.

Second group defines a rotation for all files ending with “_log”. They rotate three files when their size is over 100M.

More options can be found in logrotate man page

 
Leave a comment

Posted by on February 27, 2009 in Uncategorized

 
 
%d bloggers like this: