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

Prefork Multi Processing Module for Apache

MPM stands for Multi Processing Module and this module implements a non-threaded pre-forking web server.

MPM isolate each request , so single request wont effect any other request.

MaxRequestWorkers is proportional to Physical RAM. More value more requests so make sure we got more RAM available for that server.

=====How it Works

There is a process named as "Control Process" and it is responsible for launching child process and these child processes will listen for requests and serve them once they arrive. And Apache by default will maintain serveral spare child process so that client request doesn't have to wait until new child process created.

And following parameters are responsible for regulating these child process.
1. StartServers
2.MinSpareServers
3.MaxSpareServers
4.MaxRequestWorkers

The default value for MaxRequestWorkers is 256 , so a server with untouched MaxRequestWorkers parameter can handle 256 requests at a time and you can define your custom value according to your requirement but this proportioanl to availablity of RAM.

To have apache process to bind with port 80 , main parent process will start with root user
but all child process with start with apache to have limited access but all the content that should serve by child process should let them access it. So if some content not accessible , check whether child process which are owned by apache user&group authorized to access that content or not. Noob style just check that folder got owner ship for apache or not.

MaxConnectionsPerChild : Once a child process created , how many requests it can serve before it get killed.

MaxSpareServers Directive
-------------------------

This is the parameter to specify number of spare connection apache control process should create.
Default value is 10 and syntax is as below

Syntax: MaxSpareServers 10

If MaxSpareServers < MinSpareServers , then apache will adjust it MinSpareServers+1 automatically.

If MaxSpareServers > current Idle child/spare process then apache will kill those excessive spare process.

NOTE:
1. Dont ever set this value to a large number
2. If your website is a very busy website, turning off this is a good idea.

MinSpareServer Directive
------------------------

Syntax: MinSpareServers 5

This is the minimum threshold value of number of spare connections. If apache has found less number of spare connection than minimum threshold connections then it will create connections in per socond manner. like

1st second 2^0 connections
2nd second  2^1 connections
3rd second  2^2 connections 

like this it will move till creating 32 connections per second and once it reaches minimum spare connection threshold apache will stop creating spare connections.

Note:
1. Can turn off if your website is a very busy one.
2. Never set this parameter to a large number.

StartServers Directive
----------------------

Syntax: StartServers number

Number of child process should create at the time of Apache startup. And the default differs from
MPM to MPM.

Workder MPM has default value     3
Event  3
prefork                                             5
mpmt_os2                                       2





Tutorial on .htpasswd and .htaccess with apache(httpd) in Linux

If there is a situation that have to dealt with like a public website but with some secret information.
How can we protect the information ? .

We can use .htpasswd and .htaccess in that time.

How  ? Lets see................

Open your terminal and type as

                        vim /etc/httpd/conf/httpd.conf

and find line no : 334 to 338. This is the area of httpd.conf that dealt with .htaccess

    334 # AllowOverride controls what directives may be placed in .htaccess files.
    335 # It can be "All", "None", or any combination of the keywords:
    336 #   Options FileInfo AuthConfig Limit
    337 #
    338     AllowOverride AuthConfig
 

Now look at line no 338 , before modifying it will look like

                     AllowOverride None

You have to modify it to

                     AllowOverride AuthConfig

Now make sure that if you have some website and VirtualHost configuration of that website is successfully completed.



For my case that website is website1.com and now open your terminal and type as

                   #  vim /var/www/html/website1/protected/.htaccess

Then Write below lines

                   AuthUserFile /var/www/html/website1/protected/.htpasswd
                   AuthType basic
                   AuthName " My Personal Files"
                   Require valid-user

So what they means , here we go.....

AuthUserFile  : This is the path of .htpasswd file. Make sure you are giving proper path. If you give wrong path , it wont allow to login. Dont panic we are admins , we can make it solve by giving proper path.

AuthType : The AuthType directive selects that method that is used to authenticate the user. The most common method is Basic, and this is the method implemented by mod_auth_basic. It is important to be aware, however, that Basic authentication sends the password from the client to the server unencrypted. This method should therefore not be used for highly sensitive data, unless accompanied by mod_ssl. Apache supports one other authentication method: AuthType Digest. This method is implemented by mod_auth_digest and was intended to be more secure. This is no longer the case and the connection should be encrypted with mod_ssl instead.

AuthName : So AuthName can be anything , its the name get displayed on that password window.

Require : So this is to define to whom we have to allow to access.

For Example :

Require valid-user  # means only the valid user who are in .htpasswd file
Require raja raaz # means among the users of .htpasswd file allow only raja and raaz

But

Require valid-user raja is wrong way of usage because if you give so it doesnt make any sense.

I hope that explanation is fine. Now save and close that file and now we are going to create users for it.

# htpasswd -c /var/www/html/website1/protected/.htpasswd raja  Password

Location of htpasswd file is completely upto you but .htaccess must be inside of protected directory which intended to be protected.

To add one more user you can use this command
# htpasswd  /var/www/html/website1/protected/.htpasswd raaz  Password

If you mentioned -c here then it will overwrite old .htpasswd file. So dont  mention -c while adding one more user.
Now raja is username and Password is password to access. This will store in  /var/www/html/website1/protected/.htpasswd location. After you added user.

You can try. Just try to access  website1.com/protected in your browser and it will ask you username and password and only allowed are able to access those content.

Hope it helps.

In case of any queries please let me know.


References:

http://www.colostate.edu/~ric/htpass.html
http://www.anchor.com.au/hosting/support/password_protection_using_htaccess
http://www.seas.upenn.edu/cets/answers/auth-htpasswd.html
http://httpd.apache.org/docs/2.2/howto/auth.html


 Thank you

Virtual Hosts in Apache -Linux


############################
Listen 192.168.56.150:80
Listen 192.168.56.151:81
############################

So above two lines are stands for IP based virtual hosting and as well as Port based Virtual Host.

The virtual Host which listens to the 1st IP will browse throughh port 80 but other will listens and browse through port 81 only.

Now We have to configure Virtual Hosts

#########################################
<VirtulHost 192.168.56.150:80>
    ServerAdmin root@localhost
    DocumentRoot /var/www/website1.com
    ServerName website1.com
    ServerAlias www.website1.com
    ErrorLog logs/www.website1.com_error.log
    CustomLog logs/www.website1.com_custom.log
</VirtualHost>
###########################################

###########################################
<VirtualHost 192.168.56.151:81>
    ServerAdmin root@localhost
    DocumentRoot /var/www/website2.com
    ServerName website2.com
    ServerAlias www.website2.com
    ErrorLog log/website2.com_error.log
    CustomLog log/webiste2.com_custom.log
############################################


Note: If you dont have your DNS Server then you can make some entries like below in your /etc/hosts file
########################
# vi /etc/hosts

192.168.56.150 website1.com
192.168.56.150 www.website1.com
192.168.56.151 website2.com
192.168.56.151 www.website2.com

###############################

So Name resolution can be done.


While I am doing

##############################

# service httpd restart

##############################

I am getting error like
###########
Starting httpd: [Wed Nov 19 01:17:25 2014] [warn] VirtualHost website1.com:80 overlaps with VirtualHost userinfo.com:80, the first has precedence, perhaps you need a NameVirtualHost directive
###########

Its because I am doing name based virtual hosting with one common IP, So we have to add that IP for name based virtualhosting with a line in /etc/httpd/conf/httpd.conf

######################
NameVirtualHost XXX.XXX.XXX.XXX:PORT
######################

Then save and restart with
######################

# service httpd restart

######################

and I am sure it will be fine.