JavaTechie

Its all about Technology

Directory index forbidden by Options directive June 8, 2009

Filed under: Apache — javatechie @ 12:29 pm
Tags: ,

I was going through error log and saw this error in error log file. To solve this problem, In /etc/httpd/conf.d you will see a file entitled welcome.conf

It looks like this:

<LocationMatch “^/+$”>
Options -Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>

Change it to this:

<LocationMatch “^/+$”>
Options Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>

Just remove the hyppen(-) before the Indexes, that’s it. I hope this will solve your problem.

 

Apache 2.x + Tomcat 4.x + Load Balancing February 12, 2009

Filed under: Apache, Java — javatechie @ 10:41 am
Tags: , ,

This article contains step by step instructions for configuring an Apache 2.x web server which handles static content and delegates JSP (Java Server Pages) and Servlet requests to two Tomcat 4.x servers using AJP 13 connectors and a load balancing worker.

Introduction

Apache 2.0 is a standards compliant, fast and mature web server which excels at delivering static content such as static HTML pages and images. The Tomcat web server is great for serving Java Server Pages and servlets, but it is not as fast as Apache for delivering static content.

In order to build a fast, scalable web application, the requirements call for an Apache server that delegates servicing of JSP and servlet requests to multiple tomcat servers by using an Apache module, mod_jk, that performs load balancing with session affinity, also known as “sticky” sessions.

Session affinity explained. When a client browser requests a JSP page for the first time, the load balancer redirects the request received by Apache to one of the two tomcat servers; further requests originating from the same client session will be automatically forwarded to the same tomcat server, so that the user’s session data is retrieved.

This document describes how I configured Apache 2.x to dispatch JSP and servlet requests to two Tomcat 4.x instances listening on different ports. This setup was done on a Linux system. Your mileage may vary.

Read more

 

HOW TO Subversion+Apache on Fedora January 29, 2009

Filed under: Apache — javatechie @ 5:30 am
Tags: , ,

HOW TO Subversion+Apache on Fedora

To learn or use Subversion, please read the book.

To install subversion run below commands:

# yum install subversion
# yum install mod_dav_svn

Then you need to setup at least one repository to test it.

Here create the folders..

# mkdir /svn
# mkdir /svn/repos
# mkdir /svn/users
# mkdir /svn/permissions

repos – will contain all the projects

users – will contain all the user configs

permissions – will contain all the user permissions

We need to give these folders the proper permissions apache user permissions so that apache can write files on repos.

# chown -R apache.apache /svn

Then you can create repository using subversion cmd svnadmin.

# svnadmin create /svn/repos/project1

You can create multiple project repos under repos folder.

To setup apache server.

You may already have this subversion config file installed in conf.d folder otherwise you can create a new apache include file that will hold all configurations.

# vi /etc/httpd/conf.d/subversion.conf

This file need to contain something like this to serve the repository through apache:


LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

<Location /svn/>
DAV svn
SVNPath /svn/repos
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /svn/users/passwords
Require valid-user
AuthzSVNAccessFile /svn/permissions/svnauthz.conf

</Location>

We need to create some files so that this config will work properly. The first is htpasswd file which will contain all the usernames nad passwords which i named “/svn/users/passwords”.

# htpasswd -cb /svn/users/passwords username password

Next you need to create the svnauth file.

# vi /svn/permissions/svnauthz.conf

Inside place a list of users who have access to files:

[/]

username = rw

The “rw” states that this user has read/write access to the root repository /.

Restart your web server and you should be done.

service httpd restart

Now you should access subversion repos as below.

http://www.websitename.com/svn/repos/

 

Apache HTTPD Virtual Hosts and SSL September 25, 2008

Filed under: Apache, PHP — javatechie @ 6:29 am
Tags: ,

Apache HTTPD Virtual Hosts allow a single server to host many web sites with different addresses.

Virtual hosts are easy to set up, just check the documentation at http://httpd.apache.org/docs/ . That said, there are two main ways to configure virtual hosting, which you have to keep in mind when starting out. One method involves matching the request host name, IP address, port, or any combination of them to a separate block of HTTPD configuration statements. The other method specifies a directory pattern to use for the document root and cgi-bin based on parts of the host name.

For the former method of configuring virtual hosts, all one needs to do is add a wildcard ServerAlias directive to the VirtualHost block for your domain name.

<VirtualHost 1.2.3.4>
 ServerName domain.tld
 ServerAlias *.domain.tld
 DocumentRoot /var/www/
</VirtualHost>

For the latter, all one needs to do is match against only the domain name, or include subdomains in the pattern, making sure to create the appropriate directory structure.

VirtualDocumentRoot /var/www/%-2/
VirtualDocumentRoot /var/www/%-2/%-3/

Web hosts tend to use the larger VirtualHost method. Smaller shops, or generic mass hosts (departmental or employee hosting within an organization,for example) will find the latter very helpful, particularly when serving out of user’s home directories.

All this is great, but what about SSL? You could start up a separate instance of Apache HTTPD to serve over an SSL connection, but you probably don’t want to do that. There are some advantages, which but that is beyond the scope of this piece. The easiest way is to use a VirtualHost block to match against connections on port 443, the default HTTPS port. Contrary to popular belief, you do not need a separate IP address to do this.

<VirtualHost *:443>
 SSLEngine On
 SSLCertificateFile /etc/httpd/ssl.pem
 DocumentRoot /var/www/
</VirtualHost>

This works just fine if you are only serving one site over HTTPS. The problem comes in when you have multiple domain names being served from the same server which need SSL. Since the SSL certificate needs to be used before the web browser sends a request to the server, the server has no way of picking a domain-specific SSL certificate to use. Name-based matching just won’t work for SSL. This is why proprietors of shared web hosting services demand that you purchase a dedicated IP address if you want to use SSL. IP addresses are known before SSL certificates are used, so by matching based on IP address, we can use domain-specific SSL certificates.

<VirtualHost 1.2.3.4:443>
 SSLEngine On
 SSLCertificateFile /etc/httpd/dom1-ssl.pem
 DocumentRoot /var/www/dom1/
</VirtualHost>

<VirtualHost 1.2.3.5:443>
 SSLEngine On
 SSLCertificateFile /etc/httpd/dom2-ssl.pem
 DocumentRoot /var/www/dom2/
</VirtualHost>

So, to recap, you do not need a separate IP address to use HTTPS. You do need separate IP addresses to use HTTPS on servers with multiple domains using SSL.

 

Integrating Apache 1.3.x and Tomcat 4.x with mod_jk on Linux July 2, 2008

Filed under: Apache, Java — javatechie @ 11:18 am
Tags: , ,

This FlashGuideTM covers integrating Apache 1.3.x and Tomcat 4.x on Unix via mod_jk. These instructions have been tested on SuSE 9.0, Red Hat 6.2 and Fedora Core 2. There are two ways to integrate Apache and Tomcat: mod_jk and mod_jk2. Mod_jk is the older but more stable version, which supports load balancing and non-standard web application locations. Mod_jk2 is newer, has bugs, and, as of 11/15/04, is no longer being actively developed.

These instructions are for the current version of Tomcat 4.1.31, but have worked the same for all previous versions of Tomcat.

If you are using an older version of Tomcat, note that there are known bugs when using mod_jk and Tomcat 4.0.1 or 4.0.2, so you must use 4.0.3 or greater.

1. Building Apache 1.3.x on Linux

Unless you can find a binary distribution of Apache with DSO support enabled, you will have to follow these instructions to build it yourself.

1. Check your prerequisites:

1. You will need GCC installed
2. You will need /usr/ccs/bin and the gcc executables in your $PATH

2. Download the latest Apache source from http://httpd.apache.org/download.cgi – currently, the latest is 1.3.33.
3. Unpack the distribution into a development directory (I used /usr/local)

The distribution directory will be something like apache_1.3.33
4. Cd into the distribution directory (e.g. /usr/local/apache_1.3.33)
5. Configure the makefile:

./configure –with-layout=Apache –prefix=/usr/local/apache –enable-rule=SHARED_CORE –enable-module=so

Read More

 

Apache performance tips July 2, 2008

Filed under: Apache — javatechie @ 11:11 am
Tags: ,

Apache 2.0 was running on several Linux boxes behind a load balancer. If you ran top on each box, the CPU was mostly idle, there was plenty of memory available, and yet Apache seemed sluggish. Here are a couple of things I did to speed things up.

1. Disable RedirectMatch directives temporarily

All the Apache servers had directives such as:

RedirectMatch /abc/xyz/data http://admin.mysite.com/abc/xyz/data

This was done so administrators who visited a special URL would be redirected to a special-purpose admin server. Since the servers were pretty much serving static pages, and they were under considerable load due to a special event, I disabled the RedirectMatch directives temporarily, for the duration of the event. Result? Apache was a lot faster.

2. Increase MaxClients and ServerLimit

This is a well-known Apache performance optimization tip. Its effect is to increase the number of httpd processes available to service the HTTP requests.

The 2 entries I had in httpd.conf in the IfModule prefork.c section were:

MaxClients 1000
ServerLimit 1000

Now I have a procedure for tuning the number of httpd processes on a given box:

1. Start small, with the default MaxClients (150).
2. If Apache seems sluggish, start increasing both MaxClients and ServerLimit; restart httpd every time you do this.
3. Monitor the number of httpd processes; you can use something like:

ps -def | grep httpd | grep -v grep | wc -l

If the number of httpd processes becomes equal to the MaxClients limit you specified in httpd.conf, check your CPU and memory (via top or vmstat). If the system is not yet overloaded, go to step 2. If the system is overloaded, it’s time to put another server in the server farm behind the load balancer.

WARNING: MaxClients of 1000 exceeds ServerLimit value of 256 servers, lowering MaxClients to 256. To increase, please see the ServerLimit directive.

To avoid above warning, You need to put the Serverlimit option before the maxclient in the apache config file.

Example config:

IfModule prefork.c

StartServers 20
MinSpareServers 5
MaxSpareServers 20

ServerLimit 1024 <====—— moved this line here rather than after the
Maxclients (otherwise Apache will gives error, “WARNING: MaxClients of 1000
exceeds ServerLimit value of 256 servers, lowering MaxClients to 256. To
increase, please see the ServerLimit directive”)

MaxClients 512 <====——– changed from 256 to 512

MaxRequestsPerChild 10000

IfModule

 

Apache Performance Tuning July 2, 2008

Filed under: Apache — javatechie @ 11:03 am
Tags: ,

Apache 2.x is designed to balance flexibility, performance and portability. Apache is a good all-purpose webserver. Since Apache is designed to fit most scenarios it hasn’t been optimized to set any kind of speed records, but Apache 2.x is capable of high performance.

There have been many improvements made in Apache 2.x and many are enabled by default. But, there are some changes you can make at compile-time and run-time that can positively affect performance.

Ram is the single biggest hardware issue that determines webserver performance, so the more the better. Once a server runs out of memory it starts using the swap space on the hard drive. You never ever want have to the web server use swap. Using swap slows down of each request to such slow speeds which causes users to hit “reload”, which increases the work swap has to do, slowing it further.
So I always recommend putting in as much ram as your server can hold.

The rest of the hardware is up to you: get a fast CPU, a fast network card, and fast hard drives, you’ll have to figure out what is fast enough for you based on needs, availability and price.

You can counter, and should, control the MaxClients setting so that your server does not spawn so many children it starts swapping. This procedure for doing this is simple: determine the size of your average Apache process, by looking at your process list via a tool such as top, and divide this into your total available memory, leaving some room for other processes.

Read more

 

CURL with PHP and Apache on Windows May 20, 2008

Filed under: PHP — javatechie @ 3:39 am
Tags: , ,

Setting up cURL on Windows test box with PHP and Apache. Here is list of notes:

1. Only install PHP with the zip’d binaries. Don’t use the installer. I recommend deleting your current PHP installation and reinstalling with the binaries. Downloading the latest PHP has the added benefit of ensuring its compatible with the version of cURL you’ll download later. (I installed to D:\apps\php and will use that path for the rest of this example)

2. Edit your php.ini file:

– set extensions_dir to d:\apps\php\extensions

– set register_globals to On

– set sessions.save_path to d:\apps\php\temp (you need to create that directory first)

3. Copy php4ts.dll (located in d:\apps\php\) to your Apache bin folder

4. Copy libeay32.dll and ssleay32.dll (located in d:\apps\php\dlls\) to c:\windows\system32

5. Download cURL for Windows at: http://curl.haxx.se/download.html. I chose the Win32 – Generic by J?Hartroth. I recommend getting the SSL version in case you ever need SSL. I unzipped cURL to d:\apps\curl and will use that path for the rest of this example

6. [SSL INSTALL ONLY] Download OpenSSL for Windows from http://curl.haxx.se/download.html. (Its near the bottom of the page). Extract libssl32.dll to d:\apps\curl

7. [Windows XP Install Only] Check to see if you have the following file: c:\windows\system32\msvcr70.dll. If not, search for it in Google and download it to system32. You may get error messages without it.

8. Uncomment the curl line in your php.ini file to enable curl: extension=php_curl.dll

9. Finally edit your Apache httpd.conf file to enable php:

– Uncomment: LoadModule php4_module d:/apps/php/sapi/php4apache2.dll

– Add Line: AddType application/x-httpd-php .php

Test with the following PHP code:

$url = “http://www.thinkgeek.com”;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_VERBOSE, 1);

curl_setopt($ch, CURLOPT_POST, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

$returned = curl_exec($ch);

curl_close ($ch);

echo $returned;

SSL NOTE: I kept getting no response when I tried using curl with SSL urls. I found that adding the following solved the problem:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

I have read that the proper solution is to use the ca-bundle.crt file for curl to be able to verify certificates but I haven’t tried this yet:

curl_setopt($ch, CURLOPT_CAINFO, ‘drive:\pathto\ca-bundle.crt’);

 

Multiple Instances of Tomcat with Apache January 7, 2008

Filed under: Java — javatechie @ 6:28 am
Tags: ,

Learn how to use mod_jk to forward requests to specific hosts when more than one Tomcat instance is running.

Recently, I was asked to reorganize some of our Web applications to improve their stability. The major push was to get each of our applications running in its own instance of Tomcat. These applications all are in various stages of development, and if a single instance allocates all of the memory available, the entire Tomcat server must be restarted. This, in turn, brings down all of the other applications.
(more…)

 

Tomcat 5 on Fedora Core 6: In Five Easy Steps January 7, 2008

Filed under: Java — javatechie @ 6:25 am
Tags: , ,

Install FC6 and Apache Web Server

Stick the Fedora Core 6 DVD in and reboot. Then follow the instructions. I took all defaults where I can, including letting it “delete all Linux partitions” and automatically partition the disk. I choose to install “Web Server” and “Development Tools” when offered the chance. This installs the Apache Web Server 2.2.3 on the box.

Install Tomcat

Tomcat 5 is included in Fedora Core 6, but not installed by default. So I have to bring it in from the repository:

[root@root]# yum install tomcat5 tomcat5-webapps tomcat5-admin-webapps

This installs Tomcat 5.5.17 and a lot of their dependencies onto the system.

Read more