Apache
From Alessandro's Wiki
- Potente server web multipiattaforma
Configuration
Set a ServerName!
Bandwidth
tar zxvf mod_bw-0.7.tgz cd mod_bw apxs2 -i -a -c mod_bw.c
virtual host template
<VirtualHost 1.1.1.1:80> ServerAdmin staff@server.com ServerName server.com DocumentRoot /var/www/server.com/public_html <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/server.com/public_html > Options FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost>
logs
# Possible values include: debug,info,notice,warn,error,crit,alert,emerg. LogLevel warn CustomLog /var/www/CAMBIAMI/logs/access.log combined ErrorLog /var/www/CAMBIAMI/logs/error.log
autentication
AuthType Basic AuthName "Private Area" AuthUserFile /etc/apache2/passwords Require valid-user
force far expire
ExpiresActive On ExpiresDefault "access plus 1 year"
gzip compression
# add gzip compression / alessandro # Insert filter SetOutputFilter DEFLATE # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary # Make sure proxies don't deliver the wrong content # Header append Vary User-Agent env=!dont-vary
Cgi
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory>
charset
AddDefaultCharset UTF-8
URL Rewrite
- RewriteEngine on
- RewriteRule ^old\.html$ new.html
- RewriteRule ^old\.html$ new.html [R]
- RewriteRule ^clip/([0-9][0-9])/$ /clip.php?id=$1
- RewriteRule ^css(/)?$ /stylesheets/ [R]
Direcoty Indexes
Per ingrandire la colonna del nome del file:
IndexOptions NameWidth=*
Aggiungere un alias per esportare una directory non nella root www:
Alias /_bin "/ciao/_linux_bin/" <Directory "/ciao/_linux_bin/"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
IP filters
- Allow
Allow from 192.
- Deny
Deny from host.domain.com Deny from 192.168.0.44
- check behavior
Order deny,allow Deny from all
SSL VirtualHost
- using Gentoo distribution.
- enable ssl use flag for apache package
- edit default virtual host for a listening interface and port:
"Listen [::]:443" or "Listen 0.0.0.0:443" or Listen 192.168.82.82:443
- we want name based virtual hosts
NameVirtualHost *:443
Generating certificate
- replace the "server" name with your domain name of your website.
SRVname=server cd /etc/ssl/apache2 openssl genrsa 2048 > $SRVname.key openssl req -new -x509 -nodes -sha1 -days 365 -key $SRVname.key > $SRVname.crt
- Repeat the last step as many virtual hosts you have to serve under an ssl connection, remember to change the SRVname variable in the code:
Virtual host configuration
- example of a basic ssl virtual host:
<VirtualHost *:80> ServerName mysslvirtualhost.example.com ServerAlias mysslvirtualhost Redirect permanent / https://mysslvirtualhost.example.com/ </VirtualHost> <VirtualHost *:443> DirectoryIndex index.php # SSL SSLEngine on SSLCertificateFile /etc/ssl/apache2/server.crt SSLCertificateKeyFile /etc/ssl/apache2/server.key ServerName mysslvirtualhost.example.com ServerAlias mysslvirtualhost SSLOptions StrictRequire SSLProtocol all -SSLv2 # DocumentRoot "/var/www/mysslvirtualhost/htdocs" <Directory "/var/www/mysslvirtualhost/htdocs"> SSLRequireSSL AllowOverride All Order Deny,Allow Allow from All </Directory> CustomLog /var/log/apache2/mysslvirtualhost.log combined ErrorLog /var/log/apache2/mysslvirtualhost_error.log LogLevel warn </VirtualHost>
Proxy
- directives to have into httpd.conf or a virtual host configuration file
- permissions
<Proxy *> Order deny,allow Deny from all Allow from all </Proxy>
Reverse Proxy
ProxyPass /foo http://foo.example.com/bar ProxyPassReverse /foo http://foo.example.com/bar
Forward Proxy
ProxyRequests On ProxyVia On
Linux distribution specifics
Gentoo
- vado diretto alla versione 2:
- file di configurazione;
/etc/apache2/httpd.conf
- Directory del web default:
/var/www/localhost/htdocs
- Installarlo:
emerge -pvtD apache
controllare le USE flags che ci servono e poi
emerge apache
Fedora
- file di configurazione;
/etc/httpd/conf/httpd.conf
- Directori del web default:
/var/www/html/
- Installarlo
yum install httpd