Difference between revisions of "Apache"

From Christoph's Personal Wiki
Jump to: navigation, search
 
 
(2 intermediate revisions by the same user not shown)
Line 14: Line 14:
 
*Force [[Perl|CPAN]] to produce a list of all the modules that have updates and update them:
 
*Force [[Perl|CPAN]] to produce a list of all the modules that have updates and update them:
 
  /usr/bin/perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
 
  /usr/bin/perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
 +
 +
==Example VirtualHost domain redirect==
 +
:see: [[Rewrite engine]] for details.
 +
<!-- PRE: Start -->
 +
<Directory />
 +
  Options FollowSymLinks
 +
  AllowOverride All
 +
</Directory>
 +
 +
<VirtualHost *:80>
 +
 +
  ServerAdmin admin@example.com
 +
  ServerName  example.com
 +
  ServerAlias www.example.com
 +
 +
  # Index file and Document Root (where the public files are located)
 +
  DirectoryIndex index.html index.php
 +
  DocumentRoot /var/www/html/example.com
 +
 +
  # Rewrite rules
 +
  # Example: <nowiki>http://xtof.ch/skills</nowiki> redirects to <nowiki>http://wiki.christophchamp.com/index.php/Technical_and_Specialized_Skills</nowiki>
 +
  RewriteEngine On
 +
  RewriteRule <font color=red>^/skills$</font> <font color=green><nowiki>http://wiki.christophchamp.com/index.php/Technical_and_Specialized_Skills</nowiki></font> [R=301,L]
 +
 +
  # Custom log file locations
 +
  LogLevel warn
 +
  ErrorLog  /var/log/httpd/example.com-error.log
 +
  CustomLog /var/log/httpd/example.com-access.log combined
 +
 +
</VirtualHost>
 +
<!-- PRE: End -->
 +
 +
==Add custom headers==
 +
 +
Assuming you have [http://httpd.apache.org/docs/2.2/mod/mod_headers.html mod_headers] installed, configured, and enabled, you can add custom headers (e.g., "<code>X-My-Custom-Header</code>") to your HTTP HEAD responses.
 +
 +
* Set your customer headers to a <code>.conf</code> file (call that file whatever you like):
 +
$ cat << EOF > /etc/httpd/conf.d/custom_headers.conf
 +
Header set X-CLI "This is the tinyURL website for Christoph Champ"
 +
Header set X-Owner-URL "www.christophchamp.com"
 +
EOF
 +
 +
* Reload the Apache service:
 +
$ service httpd reload
 +
 +
* Now, check your custom headers (e.g., using [[curl]]):
 +
$ curl -I xtof.ch
 +
...
 +
X-CLI: This is the tinyURL website for Christoph Champ
 +
X-Owner-URL: www.christophchamp.com
  
 
==External links==
 
==External links==
 
*[http://httpd.apache.org/ official website]
 
*[http://httpd.apache.org/ official website]
 +
*[http://www.workingwith.me.uk/articles/scripting/mod_rewrite/ mod_rewrite, a beginner's guide (with examples)]
  
 
[[Category:Technical and Specialized Skills]]
 
[[Category:Technical and Specialized Skills]]
 
[[Category:World Wide Web]]
 
[[Category:World Wide Web]]

Latest revision as of 21:59, 17 May 2015

see: LAMP for details on installing Apache.

Error log report

  • Below is a very simple, quick way to check for (the last 100) errors in your httpd setup:
tail -100 /var/log/httpd/error_log |cut -d']' -f 4-99 |sed -e "s/, referer.*//g"|sort|uniq
  • Search for all errors:
cat /var/log/httpd/error_log |cut -d']' -f 4-99 |sed -e "s/, referer.*//g"|sort|uniq

Note: To monitor the significance, add '-c' to the uniq command, which will find you a count of the number of each error.

Configuration management

apachectl configtest

Updating modules

  • Force CPAN to produce a list of all the modules that have updates and update them:
/usr/bin/perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'

Example VirtualHost domain redirect

see: Rewrite engine for details.
<Directory />
  Options FollowSymLinks
  AllowOverride All
</Directory>

<VirtualHost *:80>

  ServerAdmin admin@example.com
  ServerName  example.com
  ServerAlias www.example.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /var/www/html/example.com

  # Rewrite rules
  # Example: http://xtof.ch/skills redirects to http://wiki.christophchamp.com/index.php/Technical_and_Specialized_Skills
  RewriteEngine On
  RewriteRule ^/skills$ http://wiki.christophchamp.com/index.php/Technical_and_Specialized_Skills [R=301,L]

  # Custom log file locations
  LogLevel warn
  ErrorLog  /var/log/httpd/example.com-error.log
  CustomLog /var/log/httpd/example.com-access.log combined

</VirtualHost>

Add custom headers

Assuming you have mod_headers installed, configured, and enabled, you can add custom headers (e.g., "X-My-Custom-Header") to your HTTP HEAD responses.

  • Set your customer headers to a .conf file (call that file whatever you like):
$ cat << EOF > /etc/httpd/conf.d/custom_headers.conf 
Header set X-CLI "This is the tinyURL website for Christoph Champ"
Header set X-Owner-URL "www.christophchamp.com"
EOF
  • Reload the Apache service:
$ service httpd reload
  • Now, check your custom headers (e.g., using curl):
$ curl -I xtof.ch
...
X-CLI: This is the tinyURL website for Christoph Champ
X-Owner-URL: www.christophchamp.com

External links