Showing posts with label Apache2 Conf. Show all posts
Showing posts with label Apache2 Conf. Show all posts

Wednesday, April 1, 2009

Securing Gitweb

We will secure Gitweb using Apache Module mod_auth_digest.

This document is based on following assumtions
  1. Apache2 is running and installed at /etc/apache2 folder
  2. gitdomain.com is already present and serving gitweb files
Assuming ,


Apache2 is run from /etc/apache2/

  • Lets created passwd file in
sudo htdigest -c /etc/apache2/passwd/digest private user1
sudo htdigest /etc/apache2/passwd/digest private user2

Note : Omit the -c flag in order to add new user information to an existing password file.

  • Enable the auth-digest sudo a2enmod auth-digest
  • Edit the gitdomain.com as following

ServerName gitdomain.com
DocumentRoot "/var/www/gitdomain.com/cgi-bin"
DirectoryIndex gitweb.cgi
SetEnv GITWEB_CONFIG /etc/gitweb.conf

ScriptAlias /cgi-bin/ /var/www/gitdomain.com/cgi-bin

Options Indexes FollowSymlinks ExecCGI
AuthType Digest
AuthName "private"
AuthUserFile /etc/apache2/passwd/digest
Require valid-user


SetHandler cgi-script


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.* /gitweb.cgi/$0 [L,PT]



Allow from all


# To debug rewrite rules, which were very painful to figure out
RewriteLog /var/log/apache2/rewrite_log
RewriteLogLevel 9

ErrorLog /var/log/apache2/gitweb

  • sudo service apache2 restart
Test it with browser if authentication is working.


Suggested Reading
http://httpd.apache.org/docs/1.3/howto/auth.html

Monday, March 23, 2009

Apache2 Tomcat6 Java MySql on Ubuntu

Check the list of Ubuntu EC2 AMIS available at http://alestic.com/
Click here to get started with launching EC2 AMIs click here

Installing JDK6, Apache And Tomcat
++++++++++++++++++++
  • apt-get update && apt-get upgrade -y
  • Install APACHE: sudo apt-get install apache2
  • Install JDK6 : sudo apt-get install sun-java6-jdk
  • Install Tomcat :
export JAVA_HOME=/usr/lib/jvm/java-6-sun
sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-examples

Test if tomcat is running
/etc/init.d/tomcat6 status

Tomcat is installed in /var/lib/tomcat6 with main files linked in /etc/tomcat6
check more about tomcat6 configuration here


Configuring Apache2 with Tomcat6
Congiruation Setup for Apache2 Virtual Host Configuration setup,by SlicetHost clicking here

At this point, I am assuming Apache2 , Java6 and Tomcat6 are installed and running fine independantly.

1. In Order to, Apache and Tomcat to talk, Mod jk connector is needed

sudo apt-get install libapache2-mod-jk
sudo a2enmod jk

2. After that, check whether there is jk.load in the apache 2 modules
sudo ls /etc/apache2/mods-enabled/

5. Edit and save the two lines of workers.properties
sudo vi /etc/libapache2-mod-jk/workers.properties
workers.tomcat_home=/usr/share/tomcat6
workers.java_home=/usr/lib/sun-java6

6. Edit and save the two lines in tomcat-users.xml
sudo vi /etc/tomcat6/tomcat-users.xml









7.
Mod_Jk configuration
  • cd /etc/apache2
  • cp /usr/share/doc/libapache2-mod-jk/httpd_example_apache2.conf mods-available/jk.conf
  • vi jk.conf and add the following
  • JkWorkersFile /etc/libapache2-mod-jk/workers.properties
    JkShmFile /var/run/apache2/jk-runtime-status
    JkLogFile /var/log/apache2/mod_jk.log
    JkLogLevel debug

8. Lets also configure Apache2 to server for Virtual Hosts

  • mkdir -p /var/www/public_html/domain1.com/{public,private,logs,cgi-bin,backup}
  • mkdir -p /var/www/public_html/domain2.com/{public,private,logs,cgi-bin,backup}
  • add some index.html files in the public directory
  • create a domain1.com file in /etc/apache2/sites-available
vi /etc/apache2/domain1.com
#domain : domain1.com
#public /var/www/public_html/domain1.com/

ServerAdmin webmaster@domain1.com

ServerName domain1.com
ServerAlias www.domain1.com
#index file sand doc root
DirectoryIndex index.html
DocumentRoot /var/www/public_html/domain1.com/public
AllowOverride All allow from all Options +Indexes
#custom log file

LogLevel info
ErrorLog /var/www/public_html/domain1.com/log/error.log
CustomLog /var/www/public_html/domain1.com/public/access.log combined

  • a2ensite domain1.com
  • /etc/init.d/apache2 reload
  • Follow the same steps for domain2.com too..
9. Test the Apache2 Virtual Hosts
  • edit the /etc/hosts file and add entries for domain1.come and domain2.com
127.0.0.1 www.domain1.com
127.0.0.1 www.domain2.com
  • Open the browser and type www.domain1.com , you should see the domain1.com/public/index.html page
11.




TOMCAT6 NOTES ON UBUNTU
+++++++++++++++++++++++
/var/lib/tomcat6/lib (CATALINA_BASE)
/usr/share/tomcat6/lib (CATALINA_HOME) (Classes are loaded from here)

Reference Links
UBuntu's apache2 file structure is different with the addition of apache2.con, mods-available, mods-enables, sites-available, sites-enabled convention. Here is a good blog which explains this direcotry structure in details, click here

Good Article on How to Configure Apache2 with Tomcat, click here

Research Links
Configuring Apache2 with Multiple Instances of Tomcat, clikc here