Configuration serveur WEB/FTP
From Tuxunix
Contents |
Serveur WEB complet sous Debian
Installation d'apache2
#> aptitude install apache2
- Configuration d'apache2, editer un fichier dans le repertoire, "/etc/apache2/site-available" par exemple : home-tuxedo.fr, exemple de fichier :
#> cat home-tuxedo.fr
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName www.home-tuxedo.fr
ServerAlias home-tuxedo.fr, *.home-tuxedo.fr
DocumentRoot /var/www/home-tuxedo.fr
<Directory /var/www/home-tuxedo.fr>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/home-tuxedo.fr/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg. LogLevel warn
CustomLog /var/log/apache2/home-tuxedo.fr/access.log combined
ServerSignature Off
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
- mettre ceci dans "/etc/apache2/httpd.conf"
#> echo "ServerName 192.168.x.x\n NameVirtualHost *:80" >> httpd.conf
- Creer le repertoire du site et du log pour ce site :
#> mkdir -p /var/www/home-tuxedo.fr #> mkdir -p /var/log/apache2/home-tuxedo.fr
- Activer le site et redemarrer apache sans couper les connexions en cours!! :
#> a2ensite home-tuxedo.fr && apache2ctl -k graceful
Installation Proftpd
Installation ProFTPD(TLS)
#> aptitude install proftpd
- Ajouter ceci au fichier "/etc/shells"
#> echo "/bin/false" >> /etc/shells
- Supprimer l'utilisateur "ftp" créé par proftpd et supprimer votre utilisateur
qui aura acces au repertoire du site
#> userdel ftp #> useradd pierre -p xxxxx -d /var/www/home-tuxedo.fr -s /bin/false
- Voici ma configuration FTP (avec TLS) :
#> cat /etc/proftpd/proftpd.conf
# /etc/proftpd/proftpd.conf -- This is a basic ProFTPD configuration file.
# To really apply changes reload proftpd after modifications.
# Includes DSO modules Include /etc/proftpd/modules.conf
# Set off to disable IPv6 support which is annoying on IPv4 only boxes.
UseIPv6 off
ServerName "tuxedo.homelinux.net"
ServerType standalone
DeferWelcome on
RequireValidShell off
RootLogin off
MultilineRFC2228 on
DefaultServer on
ShowSymlinks on
TimeoutNoTransfer 600
TimeoutStalled 600
TimeoutIdle 1200
DisplayLogin welcome.msg
DisplayFirstChdir .message
ListOptions "-l"
DenyFilter \*.*/
ExtendedLog /var/log/proftpd/ftp.log
TransferLog /var/log/proftpd/xferlog
SystemLog /var/log/syslog.log
UseFtpUsers on
DisplayLogin welcome.msg
AccessGrantMsg "welcome !!!"
AccessDenyMsg "Connection Echouee Bye Bye - Connection Refused Bye Bye"
# Lock all the users in home directory, ***** really important *****
DefaultRoot ~
MaxLoginAttempts 5
#VALID LOGINS
<Limit LOGIN>
AllowUser pierre
DenyALL
</Limit>
TransferLog /var/log/proftpd/xferlog
SystemLog /var/log/proftpd/proftpd.log
<IfModule mod_tls.c>
TLSEngine on
TLSLog /var/log/proftpd/tls.log
TLSProtocol TLSv1
TLSRequired on
TLSRSACertificateFile /etc/proftpd/ftpcert/GOOD/proftpd-rsa.pem
TLSRSACertificateKeyFile /etc/proftpd/ftpcert/GOOD/proftpd-key.pem
TLSVerifyClient off
TLSRenegotiate required off
</IfModule>
<IfModule mod_quota.c>
QuotaEngine on
</IfModule>
<IfModule mod_ratio.c>
Ratios on
</IfModule>
<IfModule mod_delay.c>
DelayEngine on
</IfModule>
<IfModule mod_ctrls.c>
ControlsEngine on
ControlsMaxClients 2
ControlsLog /var/log/proftpd/controls.log
ControlsInterval 5
ControlsSocket /var/run/proftpd/proftpd.sock
</IfModule>
<IfModule mod_ctrls_admin.c>
AdminControlsEngine on
</IfModule>
# First virtual server
<VirtualHost tuxedo.homelinux.net>
ServerName "tuxedo.homelinux.net FTP Server"
MaxClients 1 "Trop De Connections"
MaxLoginAttempts 1
# DeferWelcome prevents proftpd from displaying the servername
# until a client has authenticated.
DeferWelcome on
#MasqueradeAddress tuxedo.homelinux.net
# Limit normal user logins, because we only want to allow
# guest logins.
<Limit LOGIN>
AllowUser pierre
DenyAll
</Limit>
# Next, create a "guest" account (which could be used # by a customer to allow private access to their web site, etc)
<Directory /var/www/tuxedo.homelinux.net/>
Umask 022 022
AllowOverwrite on
<Limit READ MKD RNFR RNTO DELE RMD STOR CHMOD SITE_CHMOD SITE \ XCUP WRITE XRMD XPWD>
AllowUser pierre
DenyAll
</Limit>
</Directory>
</VirtualHost>
Creation des certificats pour l'acces TLS au FTP
#> mkdir -p /etc/proftpd/ftpcert/GOOD/ && cd /etc/proftpd/ftpcert/GOOD/ #> openssl req -new -x509 -days 365 -nodes -out proftpd-rsa.pem -keyout proftpd-key.pem
- Redemarrer le service :
#> /etc/init.d/proftpd restart
Installation Munin
#> aptitude install munin munin-node
- Mettez ce fichier dans le repertoire "/etc/apache2/site-available"
#> cat munin.fr
#NameVirtualHost munin.fr
<VirtualHost munin.fr>
ServerAdmin munin@localhost
ServerName munin.fr
DocumentRoot /var/www/munin/
<Directory /var/www/munin/>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/ </Directory> 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>
ErrorLog /var/log/apache2/munin/error.log
LogLevel warn
CustomLog /var/log/apache2/munin/access.log combined
ServerSignature Off
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options -Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
- Activer munin sous apache2 :
#> cd /etc/apache2/site-available && a2ensite munin
Monitorer Apache2
- Par defaut cela n'est pas active. Il vous faut changer dans le fichier
"/etc/apache2/apache2.conf" les lignes suivantes :
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
- Ajouter egalement la directive suivante
dans le fichier /etc/apache2/apache2.conf :
ExtendedStatus On
- Activez les modules supplementaires :
#> a2enmod info && a2enmod status
- Ensuite ajouter les plugins a Munin :
#> ln -s /usr/share/munin/plugins/apache_accesses /etc/munin/plugins/ #> ln -s /usr/share/munin/plugins/apache_processes /etc/munin/plugins/ #> ln -s /usr/share/munin/plugins/apache_volume /etc/munin/plugins/
- Redemarrer le service munin :
#> /etc/init.d/munin-node restart && apache2ctl -k graceful
Installation Fail2ban
Fail2ban est un soft, codé en Python, permettant d'analyser la quasi totalité des logs de votre systeme Linux, et, le cas échéant, de bannir les tentatives frauduleuses d'accés a votre serveur.
#> aptitude install fail2ban
D'origine, dés l'installation, si vous n'avez pas déplacé vos logs, fail2ban vous protége sinon modifier le fichier "/etc/fail2ban/jail.conf"
Installation awstats
#> aptitude install awstats
- Installer maintenant les librairies, qui vont permettre le bon fonctionnement
des plugins.
#> aptitude install libgeo-ipfree-perl libnet-ip-perl libnet-dns-perl\ liburi-perl libnet-xwhois-perl
- Maintenant nous allons activer les plugins qui nous interressent, dans le fichier
"awstats.conf"
Decommenter ces lignes :
LoadPlugin="decodeutfkeys" LoadPlugin="ipv6" LoadPlugin="geoipfree" LoadPlugin="hostinfo" LoadPlugin="urlalias" (si besoin) LogFormat=1
- Ajouter au virtualHost d'apache :
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>
ErrorLog /var/log/apache2/tuxedo.homelinux.net/error.log
LogLevel warn
CustomLog /var/log/apache2/tuxedo.homelinux.net/access.log combined
Alias /awstats-icon /usr/share/awstats/icon\
<Directory "/usr/share/awstats/icon">
AllowOverride None
Order allow,deny
Allow from all
</Directory>
- Nous allons copier le fichier awstats.conf en awstats.siteinternet.conf,
et ajouter ces directives :
LogFile=/var/log/apache2/siteinternet/access.log SiteDomain=siteinternet DefaultFile="index.php index.html" URLWithQuery=1 URLReferrerWithQuery=1
- Maintenant nous mettons en place un script de mise a jour des statistiques concu pour
gerer plusieurs fichiers de configuration d'Awstats:
#> cp /usr/share/doc/awstats/examples/awstats-update /etc/cron.hourly/ #> chmod +x /etc/cron.hourly/awstats-update
- Une fois ceci fait, vos statistiques devrait etre accessibles depuis l'URL :
http://www.siteinternet.com/cgi-bin/awstats.pl
- Enfin afin d'acceder au statistique de facon plus conviviale,
comme par exemple httt://siteinternet/stats.
Nous allons rajouter les directives de rewrite dans le vhost :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} !^(.*&)?framename=index(&.*)?$
RewriteCond %{QUERY_STRING} ^(.*&)?framename=.*(&.*)?$
RewriteRule /stats/(.*) /usr/lib/cgi-bin/awstats.pl [L]
RewriteCond %{QUERY_STRING} ^(.*&)?config=([^&]*)(&(.*))?$
RewriteRule /stats.* /stats/%2?%1%4 [R,L]
RewriteRule /stats(/awstats.pl)?$ /stats/ [R,L]
RewriteRule /stats/([^/]*)(/.*)? /usr/lib/cgi-bin/awstats.pl?config=$1 [QSA,L]
<Location /stats>
SetHandler cgi-script
# We enable auth based on login, or on IP address. Satisfy any
Order deny,allow
Deny from all
# We enable password authentication
AuthType Basic
AuthName "Advanced Web Statistics"
AuthUserFile /var/www/tuxedo.homelinux.net/stats/.htpasswd
Require valid-user
</Location>
<LocationMatch /stats/(?!awstats\.pl$)>
Require user awstats
</LocationMatch>
</IfModule>
- Voila maintenant vous pouvez acceder a vos stats via l'url suivante :

