Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Monday, December 17, 2012

How we can provide custom authentication for apache webserver

How we can achive ?
Create authen.txt with the username and password separated by colon
authen.txt
sampleuser : sampleuser
Then use the htpasswd to encrypt the password
Apache2\bin>htpasswd.exe -b authen.txt  sampleuser sampleuser 
Automatically using MD5 format.
Updating password for user testuser
Add the following in the httpd.conf file present in C:\Program Files\Apache Group\Apache2\bin
LoadModule weblogic_module modules/mod_wl128_20.so
<Location />
SetHandler weblogic-handler
WebLogicHost localhost
WebLogicPort 7001
Debug ALL
WLLogFile c:/Saple/wlproxy.log
WLTempDir c:/Saple
AuthUserFile C:/Saple/ authen.txt
AuthName “This is a protected area” 
AuthType Basic 
Require valid-user
</Location>
Also copy WL_HOME\server\plugin\win\32\mod_wl_22.so to C:\Program Files\Apache Group\Apache2\modules
Restart the Apache Server.
Now if we try to access any unprotected resource on Weblogic Server, a BASIC Authentication Window will be popped up for authentication against Apache.
If authentication is successful, the request will go through provided we set the following in the config.xml
<enforce-valid-basic-auth-credentials>false</enforce-valid-basic-auth-credentials>
Otherwise Weblogic Server will try to validate the BASIC authentication Header.

Configuring two way SSL between Client and Weblogic server with Apache proxying the request.


Configure Apache for SSL
Create the certificates using openssl (present in apache_home\bin) using the below steps:
openssl genrsa -des3 -out server.key 1024
openssl req -config ..\conf\openssl.cnf -new -key server.key -out localhost
openssl x509 -req -days 730 -in localhost -signkey server.key -out server.crt
Add the following in the httpd.conf file
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Listen 443
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile “C:\Program Files\Apache Group\Apache2\conf\server.crt”
SSLCertificateKeyFile “C:\Program Files\Apache Group\Apache2\conf\server.key”
SSLCACertificateFile “C:\Documents and Settings\Administrator\Desktop\cert\IntermediateCA.cer”
#SSLLog “C:\Program Files\Apache Group\Apache2\conf\ssl.log”
#SSLLogLevel debug
</VirtualHost>
Configure SSL between Apache and Weblogic Server
Add the following in the Location Directive
SecureProxy ON
TrustedCAFile C:\bea101\wlserver_10.0\server\lib\CertGenCA.pem
RequireSSLHostMatch false
Configure Apache to Request for Client Certificate
Add the following in the Location Directive
SSLVerifyClient optional_no_ca
SSLOptions +ExportCertData
Configure Weblogic Server for 2-way SSL
mydomain> Servers> myserver>Keystores & SSL > Advanced Options
Hostname Verification: None
Two Way Client Cert Behavior: Client Certs Requested but not enforced
Apache_SSL> Domain Wide Security Settings> Realms> myrealm> Authentication Providers> DefaultIdentityAsserter
Trusted Client Principals: provide CN of the Client Certificate
Types: X509
Details:
Use Default User Name Mapper: Checked
Default User Name Mapper Attribute Type: CN
Base64Decoding Required: Checked
Go the security realm and create a user wih the username as CN of the certificate
Add the following in the config.xml
<Server ClientCertProxyEnabled=”true”
Configure the Web Application
The Web Application should require client cert authentication.
Add the following in the web.xml
<context-param>
<param-name>weblogic.httpd.clientCertProxy</param-name>
<param-value>true</param-value>
</context-param>
Add the following in the weblogic.xml
<principal-name> CN of the certificate</principal-name>

Common Issues and solutions to errors during Apache HTTP Server startup


1. Apache HTTP Server startup issue.

2. Unable to accept incoming connections in a server machine.
 1. Apache HTTP Server startup issue.
 This is a very standard issue which is noticed while starting the ApacheHTTPServer?
service on windows. The possible reasons could be the following services. These services, if they are running, will occupy the port 80 in your machine and as a result you will not be able to start the ApacheHTTPServer  service.
a. IIS – Just stop this service before trying to start Apache on port 80 in your machine.
b. Skype – This seems to occupy the port 80 in your machine by default. If you have to use Skype in your machine, please make sure you have reconfigured your Skype to not occupy port 80.
c. OracleHTTPServer? – This service also should be stopped before starting the Apache on your machine
2. Unable to accept incoming connections in a server machine
a. Windows XP has some builtin firewall settings where all the incoming connections can be blocked. Disable this firewall setting or add the relevant port numbers as exceptions in the firewall setting.
If this is not disabled, you cannot access the application installed on the server machine.
 3. On Unix is related issue in running Apache as user root:
1. When we start Apache as “root”, Apache goes by the “User” directive in the Apache config file httpd.conf to spawn the httpd processes.
To check as what user httpd is running simply type ps -elf | grep httpd and you will see the owner of httpd (the apache process). Or you can look at owner of the httpd log files inside Apache/logs directory.
2. By default, this user will be set to username “nobody”, which will be present in most machines, but will not have enough permissions most of the time.
3. Typically “nobody” user should have access permissions to the Apache directories, if not you will get this “Forbidden error” on the page.

Common Error With Apache 2.4 on Windows 7 64 bit


Common Error With Apache 2.4

I was trying to install Apache Http Server 2.4 on Windows 7 64 bit and was receiving error while starting the Apache Server :

AH00558: httpd.exe: Could not reliably determine the server's fully qualified domain name, using XXXX::XXXX:XXXX:XXXX.
Set the 'ServerName' directive globally to suppress this message

Root Cause :

Apache Server is looking for the hostname name which it can use to start and listen for request. If there is a hostname configured on the machine and it is not configured in the httpd.conf file then it will throw this error .

Solution:

  • Get the hostname of the machine on which the Apache Server is installed using the OS command : hostname
  • Configure the same in the httpd.conf file with the directive : ServerName as shown below:
ServerName Sandeep
  • Restart the Apache Server.
In case you do not want to use the Machine Hostname with the Apache Server then make the ServerName Entry in the httpd.conf file as localhost.

Apache webserver install on Linux


Apache Webserver install on linux ( Httpd )

APACHE – WEBSERVER

The Apache HTTP Server, commonly referred to as Apache is web serversoftware notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million web site milestone. The majority of web servers using Apache run a Linux operating system.

Apache is primarily used to serve both static content and dynamic Web pages on the World Wide Web. Many web applications are designed expecting the environment and features that Apache provides.

Current Apache webserver : APACHE 2.2.14 / Release on : October 5, 2009

APACHE Httpd installation on Solaris :

1. Download the file httpd-2.2.14.tar.gz from the link :http://httpd.apache.org/

2. Unzip using command gzip –d httpd-2.2.14.tar.gz

3. UnTar the Existing file using the command tar -xvf httpd-2.2.14.tar

4. After untaring you have to go to the httpd folder cd httpd-2.2.14

5. Configure by using command which enables all the proxy modules
./configure –prefix=/opt/apache22 –enable-proxy –enable-proxy-ajp –enable-proxy-balancer –enable-proxy-http

6. If you get a gcc and make not found error, then find whether GCC is available or not by typing
echo gcc or gcc –v
echo make

if you did not find the gcc then go to the root and find the path for gcc using below command

find . -name gcc and find . –name make

after finding the path get back to httpd-2.2.14 dir and add the path,

for gcc export PATH=$PATH:/usr/sfw/bin
for make export PATH=$PATH:/usr/ccs/bin

and now you can configure
After configuring type the command make

7. After make the type the command make install

8. Installation is completed. Now operate the apache . To start the apache go to the bin folder cd /opt/apache22/bin
Type ./apachectl start (stop/restart)

If you have the problem with the ports then change the port numbers in httpd.conf file, after changing the port restart the apache

Most of us had a general error ” server not found”.
To fix this open main configuration file with vi editor and un comment the line “server name pc name com:80″

Now try again and restart the apache.
Now goto webbrowser and type http://localhost/ If the page displays IT WORKS then the apache is working perfectly.

Mod_jk connector to connect Webserver & Appserver


Mod_Jk Connector to connect web server(Apache) to application server (Tomcat)
Mod_jk is used to connect apache webserver with tomcat application server

Download the mod_jk connector from

Extract the file using below command
tar -xzvf apache-tomcat-6.0.18.tar.gz

Add the path of apxs to the env $PATH by
export PATH=$PATH:/home/subha/apps/webserver/httpd-2.2.11/bin/apxs

Go to this folder
cd tomcat-connectors-1.2.27-src/native
./configure  –with-apxs=/home/subha/apps/webserver/httpd-2.2.11/bin/apxs
make
make install (assuming the user is root)

Copy the file mod_jk.so to httpd-2.2.11/modules/ (if not already present)
-   vi /httpd-2.2.11/conf/workers.properties

Paste the following output into the file:
.tomcat_home=/home/subha/apps/appserver/apache-tomcat-6.0.18
workers.java_home=/usr/bin/java
ps=/
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=worker1

-   vi httpd.conf
-   Append the following to httpd.conf
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /home/subha/apps/webserver/httpd-2.2.11/conf/workers.properties
JkLogFile /home/subha/apps/appserver/apache-tomcat- 6.0.18/logs/mod_jk.log
JkLogLevel debug
JkMount /sample/* worker1
JkMount /sample1/* worker1
JkMount /servlet/* worker1
JkMount /*.jsp worker1
-   Test by http://localhost/sample/

Apache ANT Install


APACHE ANT INSTALL

Apache Ant is a software tool for automating software build processes. It is similar toMake but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects.

INSTALL -ANT

After doing tar and gzip then start doing it

[subha@VF1 ant]$  export ANT_HOME=/home/subha/ant/apache-ant-1.8.0

[subha@VF1 ant]$ ls
[subha@VF1 ant]$ cd /usr/java/
[subha@VF1 java]$ ls
default  jdk1.6.0_16  latest
[subha@VF1 java]$ cd
[subha@VF1 ~]$ ls
ant                          apacheappserver  jboss
apache-ant-1.8.0-bin.tar.gz  apachewebserver  vijay

[subha@VF1 ~]$ export JAVA_HOME=/usr/java/jdk1.6.0_16/
[subha@VF1 ~]$ ls
[subha@VF1 ~]$ ant
-bash: ant: command not found

[subha@VF1 ~]$ export PATH=$PATH:/home/subha/ant/apache-ant-1.8.0/bin
[subha@VF1 ~]$ ant
Buildfile: build.xml does not exist!
Build failed

create build.xml in the bin directory and copy the below 5 lines in that build.xml

<project name=”MyProject” basedir=”.”>
<description>
simple example build file
</description>
</project>

[subha@VF1 bin]$ ant
it says BUILD SUCCESSFUL