Installing NginX as Frontend to Apache for ISPCP [Part 1]

0

Part1 – Installing Nginx with upload modult from source

ในส่วนนี้เป็นการติดตั้ง nginx

1. just init script we need

apt-get install nginx
apt-get remove nginx

2. download upload-module from http://www.grid.net.ru/nginx/upload.en.html

wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.12.tar.gz
tar xvfz nginx_upload_module-2.0.12.tar.gz
mv nginx_upload_module-2.0.12 /usr/src/

3. download nginx

wget http://nginx.org/download/nginx-1.0.3.tar.gz
tar xvfz nginx-1.0.3.tar.gz
cd nginx-1.0.3

4. configure and install

./configure –sbin-path=/usr/sbin –conf-path=/etc/nginx/nginx.conf –with-http_gzip_static_module –group=www-data –user=www-data –pid-path=/var/run/nginx.pid –with-http_stub_status_module –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log

make -j8  (j = number of core)
make install

5. create nginx user

adduser –system –no-create-home –disabled-login –disabled-password –group nginx

Reference
http://www.punteney.com/writes/setting-django-slicehost-ubuntu-hardy-postgres-apa/

http://library.linode.com/web-servers/nginx/installation/ubuntu-9.10-karmic

Advertisements

Installing NginX as Frontend to Apache for ISPCP [Part 2]

0

Part2 – NginX with Php fastcgi

ในส่วนนี้เป็นการติดตั้ง nginx ให้สามารถใช้งาน php ได้
ในความจริงแล้วไม่จำเป็นต้องติดตั้ง php ในส่วนนี้ เพราะเราจะใช้ apache เป็น backend สำหรับ php/mysql อยู่แล้ว
แต่เนื่องจากผมจำเป็นต้องใช้สำหรับส่วนการสตรีมมิ่งไฟล์ครับ สำหรับวิธีการติดตั้ง มีดั้งนี้

1. vi /etc/php5/cgi/php.ini

cgi.fix_pathinfo = 1

2. vi /etc/nginx/sites-available/default

location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default$fastcgi_script_name;
}

3. install lighttpd for /usr/bin/spawn-fcgi, which we can use to start FastCGI processes

aptitude install lighttpd

4. we not need lighttpd to run

update-rc.d -f lighttpd remove

5. create spawn startup file

touch /usr/bin/php-fastcgi
vi /usr/bin/php-fastcgi

#!/bin/sh
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -f /usr/bin/php5-cgi

 touch /etc/init.d/init-fastcgi
vi /etc/init.d/init-fastcgi

#!/bin/bash
PHP_SCRIPT=/usr/bin/php-fastcgi
RETVAL=0
case “$1” in
    start)
      $PHP_SCRIPT
      RETVAL=$?
  ;;
    stop)
      killall -9 php
      RETVAL=$?
  ;;
    restart)
      killall -9 php
      $PHP_SCRIPT
      RETVAL=$?
  ;;
    *)
      echo “Usage: php-fastcgi {start|stop|restart}”
      exit 1
  ;;
esac      
exit $RETVAL

chmod 755 /usr/bin/php-fastcgi
chmod 755 /etc/init.d/init-fastcgi

/etc/init.d/init-fastcgi start

6. set to run as boot

 update-rc.d init-fastcgi defaults

Reference
http://www.howtoforge.com/nginx_php5_fast_cgi_xcache_ubuntu7.04
http://www.howtoforge.com/installing-nginx-with-php5-and-mysql-support-on-debian-lenny

How to install Tomcat6 + Mod_JK

0
เริ่มต้นติดตั้ง Java และ jsvc
apt-get update
apt-get install sun-java6-jdk jsvc

ดาวน์โหลด Tomcat6
cd /usr/src
wget http://mirror.kapook.com/apache/tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29-deployer.tar.gz

แตกไฟล์ และย้ายไปที่ /usr/share
tar zxvf apache-tomcat-6.0.29.tar.gz
cd apache-tomcat-6.0.29
mv
apache-tomcat-6.0.29 /usr/share/tomcat6

เพิ่ม user และกำหนดสิทธิ์
useradd tomcat6
chown -R tomcat6: /usr/share/tomcat6


สร้างไฟล์เพื่อเรียกใช้งาน
vi /etc/init.d/tomcat6
export JAVA_HOME=/usr/lib/jvm/java-6-sun

case $1 in
start)

sh /usr/share/tomcat6/bin/startup.sh
;;

stop)

sh /usr/share/tomcat6/bin/shutdown.sh
;;

restart)

sh /usr/share/tomcat6/bin/shutdown.sh
sh /usr/share/tomcat6/bin/startup.sh
;;

esac

exit 0

chmod +x /etc/init.d/tomcat6

กำหนดให้ทำงานทุกครั้งที่เปิดเครื่อง
update-rc.d tomcat6 defaults

ลองทดสอบ
/etc/init.d/tomcat6 start

wget http://localhost:8080

ตั้งค่าในไฟล์ server.xml
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListen
er" />
  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListe
ner"/>
 
  <!– Global JNDI resources –>
  <GlobalNamingResources>
 
    <!– Test entry for demonstration purposes –>
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
 
    <!– Editable user database that can also be used by
         UserDatabaseRealm to authenticate users –>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
       description="User database that can be updated and saved"
           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />
 
  </GlobalNamingResources>
 
 
  <!– Define the Tomcat Stand-Alone Service –>
  <Service name="Catalina">
 
    <!– A "Connector" represents an endpoint by which requests are received
         and responses are returned.  Each Connector passes requests on to the
         associated "Container" (normally an Engine) for processing.
    –>
 
    <!– Define a non-SSL HTTP/1.1 Connector on port 2117 (default 8080) –>
    <!– <Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="5" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />–>
 
    <!– Define an AJP 1.3 Connector on port 8009 –>
    <Connector port="8009"
               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
 
    <!– Define a Proxied HTTP/1.1 Connector on port 8082 –>
    <!– See proxy documentation for more information about using this. –>
    <!–
    <Connector port="8082"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" acceptCount="100" connectionTimeout="20000"
               proxyPort="80" disableUploadTimeout="true" />
    –>
 
    <!– An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host). –>
     
    <!– Define the top level container in our container hierarchy –>
    <Engine name="Catalina" defaultHost="localhost">
 
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>
 
      <!– Define the default virtual host –>
      <Host name="www.example.com" appBase="/var/www/example.com/htdocs"
        unpackWARs="true" autoDeploy="true">
 
        <Context path="" docBase="appname" debug="0" reloadable="true"/>
 
        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="example.com_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>
      </Host>     
    </Engine>
  </Service>
</Server>
ติดตั้ง mod_jk
apt-get install libapache2-mod-jk


Enable wildcard domain in IspCP

0
IspCp not support for wildcard domain.
when you try to Add DNS zone’s record name *.yourdomain.com

Cannot validate A record. Reason ‘Use of disallowed char("*") in NAME’.

To Solve this, we need to
Edit function validate_NAME :

vi /var/www/ispcp/gui/client/dns_edit.php

add this :

function validate_NAME($domain, &$err) {
        if($domain[‘name’]=="*"){
                return true;
        }
        if (preg_match(‘~([^-a-z,A-Z,0-9.])~u’, $domain[‘name’], $e)) {
                $err .= sprintf(tr(‘Use of disallowed char("%s") in NAME’), $e[1]);
                return false;
        }
        if (preg_match(‘/\.$/’, $domain[‘name’])) {
                if (!preg_match(‘/’.str_replace(‘.’, ‘\.’, $domain[‘domain’]).’\.$/’, $domain[‘name’])) {
                        $err .= sprintf(tr(‘Record "%s" is not part of domain "%s".’, $domain[‘name’], $domain[‘domain’]));
                        return false;
                }
        }
        return true;
}

Now you can add wildcard domain.

Setup NTP Linux datetime

0

Synchronize the System Clock

It is a good idea to synchronize the system clock with an NTP (network time protocol) server over the Internet. Simply run

aptitude install ntp ntpdate

Configure Timezone

Find your timezone file under /usr/share/zoneinfo. For example:

/usr/share/zoneinfo/Asia/Bangkok

Create a symbolic link from the appropiate timezone to /etc/localtime.

ln -sf /usr/share/zoneinfo/Asia/Bangkok /etc/localtime

Configure NTP Server

The configuration file for ntpd is located at /etc/ntp.conf. The
default Ubuntu file probably requires some modification for optimal performance.You need to edit the /etc/ntp.conf file using the following command

vi /etc/ntp.conf

server time1.nimt.or.th
server time2.nimt.or.th
server time3.nimt.or.th

Now Restart ntp service using the following command

/etc/init.d/ntp restart

Set the hardware clock to the system time:

/sbin/hwclock –systohc