# /etc/apache2/
# |-- apache2.conf# | `-- ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf.d
# | `-- *
# `-- sites-enabled
# `-- *
**Struture of config in Debian is different from other linux dist.
** apache2.conf is the main config file
it includes other files (mods-enabled/*, conf.d/*, sites-enabled,ports.conf)
** ports.conf
ports to listen to
Directives: Timeout, Keepalive,AccessFileName ........
Configuration Section Containers:
|
|---evaluted each request : <VirtualHost> <Directory>....
| |
| |--Filesystem cotainer:<Directory> <Files>.....
| |
| `--Webspace Container: <Location>......
|
`---evaluated at startup: <IfDefine> <IfModule> ....
Directives Scoping: Limit the scope of effect of directives(w/SectionContainer)
.htaccess: Placed in DocumentDirectory, use directives to immediately affect access
Administrator can limit directives in .htaccess by AllowOverride Directive
Virtual Hosting
How apache selects virtual to respond to request
1. Find best matching <VirtualHost> based on IP addr
2. More than 1 match--> compare ServerName and ServerAlias
3. No match found --> handled by global server config
#sites-available/000-example
How apache selects virtual to respond to request
1. Find best matching <VirtualHost> based on IP addr
2. More than 1 match--> compare ServerName and ServerAlias
3. No match found --> handled by global server config
#sites-available/000-example
<VirtualHost *:80>
`--- Placing IP rather than DN in this directive
ServerName www.example.org ß FQDN of server
`--- Placing IP rather than DN in this directive
ServerName www.example.org ß FQDN of server
ServerAdmin webmaster@localhost ß admin mail
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml
`--- index files to look for
DocumentRoot /var/www ß root directory of site
Alias /mydoc /var/local/lib/mydata
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
`----Additional option for Directory
AllowOverride None
`----.htaccess (Only available under Directory)
Order allow,deny
allow from all
|----.Search allow first, then deny, deny overwrites allow
`----Rule not found --> deny
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <--CGI Scripts location
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
|------ExecCGI à CGI script
|------MultiViews HTTP1.1 content negotiation
`------SymLinksIfOwnerMatch stricter symlink follow
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName other.example.com ßanother virtual host
ServerAlias other.example.com *.other.example.com
`--another way is set ServerAlias
DocumentRoot /www/otherdomain
</VirtualHost>
<VirtualHost _default_:80> <--catching request not matching any vhost
DocumentRoot /www/default
</VirtualHost>
Listen 8080 <--Listen directive should be placed here or in port.conf
Listen 9090
<VirtualHost *:8080 *:9090>
DocumentRoot /www/default
</VirtualHost>
UserDir Module
Mods-available/userdir.conf
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
</Directory>
</IfModule>
CGI Dynamic Content w/ PHP,Python,Perl
$apt-get install libapache2-mod-[php,perl,python]
.htaccess
.htaccess
*place directives
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Option +Indexes –FollowSymLinks
IndexOptions +FancyIndexing
IndexIgnore *.php *.exe
*Rewirte Request URL (Requires mod_rewrite and override allowed)
.htaccess
RewriteEngine on
RewriteBase /myApp <---- base URL for per-directory rewrites
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
`----only rewrite when HOST matches(NC flag = no case)
RewriteBase /myApp <---- base URL for per-directory rewrites
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
`----only rewrite when HOST matches(NC flag = no case)
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/?(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R,NE]
|----
|---- (flag: L -> Stop the rewriting process immediately and don't apply any more rules)
|---- (flag: R -> Forces an external redirect)
|----
$N
(0 <= N <= 9) -> back references|---- (flag: L -> Stop the rewriting process immediately and don't apply any more rules)
|---- (flag: R -> Forces an external redirect)
`----( flag: NE: noescap -> especial characters, such as
&
and ?
, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.)
沒有留言:
張貼留言