Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Apache Web Server Setup 3


Published on

Published in: Technology
  • Be the first to comment

Apache Web Server Setup 3

  1. 1. Meeting 3: Advanced Apache Topics Rutgers University Internet Institute Instructor: Chris Uriarte (non IPVH exc)
  2. 2. Virtual Hosting <ul><li>General term used when you run more than one website on a single system. </li></ul><ul><li>Allows ISPs and hosting providers to make money by sharing resources among clients. Allows companies and individuals to save time and money - a single machine can host many websites. </li></ul>
  3. 3. Options for Hosting More than One Website on a Single System <ul><li>Run separate instances of httpd servers: httpd –f /usr/local/apache/conf/httpd-virtual.conf </li></ul><ul><li>Run a server that will listen on multiple ports and serve different content depending on the port. </li></ul><ul><li>True Virtual Hosting - Allows multiple IP address and/or host names to be served through a single Apache server. </li></ul><ul><ul><li>IP-Based </li></ul></ul><ul><ul><li>Name-Based (not supported by very early Web browsers…Netscape 2.0/IE 3.0) </li></ul></ul>
  4. 4. Virtual Hosting: IP Based <ul><li>You must configure your machine to “listen” for multiple IP addresses. One NIC binds to multiple IP addresses </li></ul><ul><li>One hostname is associated with each IP address </li></ul> SERVER NIC
  5. 5. Virtual Hosting: Name Based <ul><li>A machine can host multiple websites using only 1 IP address </li></ul><ul><li>All hostnames have the same IP address </li></ul><ul><li>Becoming more and more popular. </li></ul> SERVER NIC
  6. 6. Setting-Up IP-Based Virtual Hosting: An Overview <ul><li>Once you have secured the domain names/hostnames you want to use for your website, you need to assign each of them a unique IP address. </li></ul><ul><li>Some ISPs can assign you additional IP addresses. </li></ul><ul><li>Blocks of IP addresses are usually assigned with business T1s or DSL lines. </li></ul>
  7. 7. Setting-Up IP-Based Virtual Hosting, Con’t. <ul><li>You need to have DNS properly configured for your domains, e.g. The world needs to know that is at the IP address </li></ul><ul><li>Remember, your ISP can usually provide DNS service for your domains. </li></ul>
  8. 8. IP-Based Virtual Hosting: Setting Up Your Machine <ul><li>Your web server needs to be configured to listen for the IP addresses related to your websites: </li></ul><ul><li>UNIX-based OSs allow you to configure multiple IP addresses using the ifconfig command (must be run as root) </li></ul><ul><li>Usage: ifconfig interface:<sub-number> IP </li></ul><ul><ul><li>e.g: ifconfig eth0:0 </li></ul></ul><ul><ul><li>ifconfig eth0:1 </li></ul></ul><ul><li>WinNT IP setup through Network control panel. </li></ul>
  9. 9. Configuring Apache for IP-Based Virtual Hosting <ul><li>Configuring Apache for Virtual Hosting is quite simple: Simply add a <VirtualHost> block within the httpd.conf file. </li></ul><ul><li>Format: </li></ul><ul><ul><li><VirtualHost IP-or-HOSTNAME:Port> </li></ul></ul><ul><ul><li>#Any Valid httpd.conf directives </li></ul></ul><ul><ul><li></VirtualHost> </li></ul></ul><ul><li>Required for each Virtual Host website your are using…therefore your httpd.conf can have multiple <VirtualHost> blocks. </li></ul>
  10. 10. IP-Based VH Configuration con’t. <ul><li>Typical <VirtualHost> block in httpd.conf: </li></ul><ul><li><VirtualHost> </li></ul><ul><li>DocumentRoot /home/www/bearsnest/htdocs </li></ul><ul><li>ServerAdmin </li></ul><ul><li>ServerName </li></ul><ul><li>ErrorLog logs/bears-error_log </li></ul><ul><li>TransferLog logs/bears-access_log </li></ul><ul><li>Redirect /adprotech </li></ul><ul><li>Alias /staff /home/staff/chrisjur/htdocs/bn/staff </li></ul><ul><li></VirtualHost> </li></ul><ul><li>The key: Vitual hosts will have their own unique DocumentRoot – different content for different sties. </li></ul>
  11. 11. Steps for Setting-Up Name-Based Virtual Hosting <ul><li>When setting up Name-based virtual hosts, you need to add the special NameVirtialHost Directive to your httpd.conf: </li></ul><ul><ul><li>NameVirtualHost <Your IP Address> </li></ul></ul><ul><li>Which tells Apache the single IP address you will use for all your websites. </li></ul><ul><li>Now simply add <VirtualHost> blocks for each of your website domains. </li></ul>
  12. 12. Name-Based VH Examples <ul><li>NameVirtualHost </li></ul><ul><li><VirtualHost> </li></ul><ul><li>DocumentRoot /home/www/yoursite/htdocs </li></ul><ul><li>ServerAdmin </li></ul><ul><li>ServerName </li></ul><ul><li>ErrorLog logs/yoursite-error_log </li></ul><ul><li></VirtualHost> </li></ul><ul><li><VirtualHost> </li></ul><ul><li>DocumentRoot /home/www/mysite/htdocs </li></ul><ul><li>ServerAdmin </li></ul><ul><li>ServerName </li></ul><ul><li>ErrorLog logs/mysite-error_log </li></ul><ul><li></VirtualHost> </li></ul>
  13. 13. Virtual Hosting Recap <ul><li>Get your DNS configured for each domain </li></ul><ul><li>IP-based Virtual Hosting vs. Name-based Virtual Hosting </li></ul><ul><li>Configure your server for multiple IP addresses if using IP-based Virtual Hosting </li></ul><ul><li>Create new directories for new Document Roots </li></ul><ul><li>Add <VirtualHost> blocks to your httpd.conf </li></ul>
  14. 14. Delivering Dynamic Content <ul><li>Two ways of delivering dynamic content for the Web: client-side or server-side technologies </li></ul><ul><li>Client-Side </li></ul><ul><ul><li>Elements are downloaded to the browser and execute on the client’s system. </li></ul></ul><ul><ul><li>Examples: JavaScript, Java Applets, client-side image maps. </li></ul></ul><ul><ul><li>Web server administrator needs to see that MIME types are set correctly. </li></ul></ul>
  15. 15. Dynamic Content, con’t. <ul><li>Server-Side </li></ul><ul><ul><li>Server processes “on-the-fly” content that is passed to client browser. </li></ul></ul><ul><ul><li>Examples: server-side includes, CGI (Common Gateway Interface), server-side image maps, ASP (Active Server Pages), Java Servlets. PHP </li></ul></ul><ul><ul><li>Server-side technologies generally require additional configuration of the Web server in order to function properly. Usually require specific Apache modules. </li></ul></ul><ul><ul><li>Enabling server-side technologies generally has security implications. </li></ul></ul>
  16. 16. Server-Side Includes <ul><li>Server-side includes are directives that can be placed in HTML documents to execute other programs or to output data. </li></ul><ul><li>Requires mod_include. </li></ul><ul><li>To enable SSI, make the following modifications to httpd.conf: </li></ul><ul><ul><li>Options Includes (or IncludesNOEXEC) </li></ul></ul><ul><li>The options directive only works within a specific Directory or VirtualHost container. </li></ul>
  17. 17. Enabling Server Side Includes, con’t… <ul><li>To tell Apache how to interpret SSI documents, add the following to httpd.conf: </li></ul><ul><ul><li>AddType text/html .shtml </li></ul></ul><ul><ul><li>AddHandler server-parsed .shtml </li></ul></ul><ul><li>These lines are usually commented out by default, so you just need to uncomment them. </li></ul><ul><li>All files with indicated extension(s) will be parsed by Apache server prior to being transmitted to the client, e.g. web page files that end with .shtml can contain SSI’s. </li></ul>
  18. 18. Server-Side Includes Examples <ul><li>The general form of the SSI directive is: <!--#command parameter=“value”--> For example: </li></ul><ul><ul><li><!—include file=“include.html”--> </li></ul></ul><ul><ul><li>Will insert the contents of the file file “include.html” when displayed in the client’s browser. </li></ul></ul><ul><ul><li><!—echo var=“LAST_MODIFIED”--> </li></ul></ul><ul><ul><li>Prints the last time your HTML file was modified. </li></ul></ul>
  19. 19. Server Side Includes, con’t. <ul><li>The Server Side Include in the .html file is evaluated by Apache and the output is displayed to the client. </li></ul><ul><li>Check out http:// for an example ( source file is /home/staff/chrisjur/public_html/ssi.shtml on server) </li></ul>
  20. 20. CGI <ul><li>CGI (Common Gateway Interface) is a protocol for getting, processing, and returning information through Web pages. </li></ul><ul><li>CGI programs or scripts can be written in a variety of languages including Perl, Python, VB Script, JavaScript, and C. </li></ul><ul><li>CGI scripts are generally triggered by data supplied by the client. </li></ul>
  21. 21. Enabling CGI <ul><li>There are two ways to enable Apache to recognize CGI scripts: </li></ul><ul><ul><li>To allow CGI scripts in one system-wide directory outside of the document root (All CGI programs must be placed in one directory): </li></ul></ul><ul><ul><ul><li>ScriptAlias /cgi-bin “/home/students/<username>/apache/cgi-bin/” </li></ul></ul></ul><ul><ul><li>Within a container: </li></ul></ul><ul><ul><ul><li>Options ExecCGI <other options> </li></ul></ul></ul><ul><ul><ul><li>SetHandler cgi-script </li></ul></ul></ul><ul><ul><li>To enable files with only specific extensions as CGI scripts use AddHandler instead of </li></ul></ul><ul><ul><ul><li>SetHandler: AddHandler cgi-script .cgi </li></ul></ul></ul>
  22. 22. Enabling CGI: Example 1 <ul><li>Sometimes it’s convenient to have one centrialized “cgi-bin” directory where all CGI programs are kept. </li></ul><ul><li>You can access all the scripts through </li></ul><ul><li>To do this at the following line to httpd.conf: </li></ul><ul><li>ScriptAlias /cgi-bin “/home/students/<username>/apache/cgi-bin/” </li></ul>
  23. 23. Enabling CGI: Example 2 <ul><li>You can enable CGI scripts to be placed in any directory by specifying some CGI directives in a directory container within the httpd.conf or an .htaccess file. This allows CGI execution in the directory specified: </li></ul><ul><li><Directory /home/user/htdocs> </li></ul><ul><li>Options ExecCGI (other options…) </li></ul><ul><li>SetHandler cgi-script </li></ul><ul><li></Directory> </li></ul>
  24. 24. Limiting CGI Access <ul><li>If you do not have Options ExecCGI or a ScriptAlias directive, the execution of CGI programs will be denied. </li></ul><ul><li>You can limit CGI access to only programs that end with a specific extension: </li></ul><ul><ul><li>SetHandler: AddHandler cgi-script .cgi </li></ul></ul><ul><li>(limits CGI execution to programs that only end in .cgi) </li></ul>
  25. 25. CGI: Examples <ul><li> - CGI script written in Perl, simply outputs current time and the end-user’s browser type (source at /home/staff/chrisjur/public_html/cgi-bin/test.cgi) </li></ul><ul><li> - Written as a shell script in, prints current date/time and lists files in its directories (source at /home/staff/chrisjur/public_html/cgi-bin/shell.cgi) </li></ul>
  26. 26. More CGI Examples… <ul><li>http:// - More traditional example of what CGI is used for. An HTML form posts to a CGI script written in Perl (/home/staff/chrisjur/public_html/cgi-bin/feedback.cgi) which emails form contents to a recipient and performs some validation logic. </li></ul>
  27. 27. Exercise: Enabling CGI <ul><li>Enable CGI via the ScriptAlias directive in your httpd.conf. Specify a cgi-bin directory to place all your CGI scripts. </li></ul><ul><li>Copy /home/staff/chrisjur/test.cgi script to your cgi-bin directory. Make the test.cgi script executeable (chmod a+x test.cgi) </li></ul><ul><li>Access the script via </li></ul>