Apache
Jump to navigation
Jump to search
Example Vhost Configurations
Generic http
<VirtualHost *:80> ServerName foo.com ServerAlias *.foo.com DocumentRoot "/www/files/foo" ErrorLog /www/logs/foo.com.error_log CustomLog /www/logs/foo.com.access_log combined </VirtualHost>
Note, I usually put the following in httpd.conf to keep the individual virtualhosts un-cluttered, since all my sites have the parent same doc root:
ServerAdmin me@me.com <Directory "/www/files"> Options FollowSymLinks MultiViews Order allow,deny Allow from all </Directory>
Generic SSL
<VirtualHost 10.0.0.65:443> ServerName secure.foo.com DocumentRoot "/www/files/foo" ErrorLog /www/logs/secure.foo.com.error_log CustomLog /www/logs/secure.foo.com.access_log combined SSLEngine on SSLProtocol all -SSLv2 SSLCipherSuite SSLv3:+HIGH:+MEDIUM #Network Solutions is where i get my ssl certs, they require chaining SSLCertificateFile /usr/local/apache2/ssl.certs/secure.foo.com.crt SSLCertificateChainFile /usr/local/apache2/ssl.certs/secure.foo.com.NetworkSolutions_CA.crt SSLCertificateKeyFile /usr/local/apache2/conf/ssl.certs/secure.foo.com.key <FilesMatch "\.(cgi|shtml|phtml|php3?)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory "/www/files/foo"> SSLOptions +StdEnvVars Options FollowSymLinks MultiViews AllowOverride None Order allow,deny Allow from all </Directory> SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade </VirtualHost>
Redirects
Basic
#Simple Redirect 301 /main/do/Careers http://www.dominionenterprises.com/careers #For url with a space RewriteRule ^main/do/businesses/id/4/category/For(\ |%20)Consumers http://www.dominionenterprises.com/our-brands/recruitment [R=301,L]
http to https
<VirtualHost *:80> ServerName secure.foo.com RewriteEngine On RewriteRule (.*) https://my.cycletrader.com$1 </VirtualHost>
Issues
Semaphores on CentOS
Sometimes a system will run out of semaphores, apache causes this pretty often on centos 5, resulting in this error:
[emerg] (28)No space left on device: Couldn't create accept lock
Even though there is plenty of disk space for logs & whatnot. To see the semaphores an apache process is using:
ipcs -s | grep apache
And to remove them:
ipcs -s | grep apache | awk ' { print $2 } ' | xargs ipcrm sem
HowTo
- Show which MPM is in use: httpd -V | grep MPM