TimeLinux1

Sunday, April 10, 2011

Linux: Apache - 2

... continued ...

Setting up Apache:
-first make a backup copy of /etc/httpd/conf/httpd.conf
-in RHEL/Fedora, run 'system-config-httpd' utility--it is simpler than editing httpd.conf file directly.
-you can setup Apache to listen simultaneously at multiple ip/ports by setting the 'Listen' directive.
-eg:    Listen    80                [ localhost ]
    Listen    192.168.1.1:8070
-the ServerName directive sets the FQDN for the Apache webserver
-eg:    ServerName www.example.com:80
-besides the above, you can set other important directives like ServerAdmin and DocumentRoot.
-then there are multiple optional/additional directives for MaxClients, Timeout, Errorlog etc..
-Dont forget the restart of Apache httpd daemon.
    # /sbin/service httpd restart | start | stop | graceful

-Redirects:
-Apache can respond to a request for an URI by asking the client to request a different URI. This is called 'redirect'.
-This works because redirection is part of http implementation.
-This is especially useful in cases of website-moves or new page additions.
-The ServerName and UseCanonicalName directives of the httpd.conf file are used in redirection.

-Virtual Hosts:
-Virtual hosts allow one instance of Apache to requests directed to multiple IP/hosts as if they were multiple servers.
-Each virtual host can then server different content.
-virtual hosts can be set up by 'name' or by 'IP address'.
-virtual hosts by name are useful if you have only one shared IP address.
-virtual hosts are defined in the <VirtualHost> container of httpd.conf.
-in this container you can define new ServerName, DocumentRoot and other directives, different from the main server.

-Troubleshooting:
-Some useful Apache Troubleshooting commands:
    # /sbin/service http configtest           - checks syntax of httpd.conf file
    # /sbin/service httpd status               - checks all the httpd daemon status
    # telnet <ip addr> 80                       - to verify client browser is functional
    # cat .htaccess                                   - verifies authentication directives to restrict access to web pages
    # htpasswd -c .htpasswd mrinal        - sets new password for user mrinal (-c = change)
Note: the typical location for .htpasswd file is /var/www/.htpasswd

No comments:

Post a Comment