Serveur Web Apache - Site de Gérald Grévrend
Transcription
Serveur Web Apache - Site de Gérald Grévrend
! % % & ' " $ 1 4 5 % ' ( ) ' * )+ ' , '' % & )+ '" % & -./ '$ 0 &) ) '1 0 2 * 3 '1 ) '1 * & , '4 / , ) '4 &) '4 / , ) '4 / , ) . '4' / , ) , '5 0 &) '5 '5 '5 0 , ' 6 ' / ' & ' ( 7 ' ' 6 * & ' " 0 ' $ / + 66! ' 1 ! ) 6 66! " , " 0 &) " 0 &) ) .8. , 0 2 * ) 4 % . . 4 % / " 6 , * , 9: , &) * * 3 % % % ;# # < = % ;# # ) = , & ! & 9: , &) 66! 8 & % & % & 66! 2 * 3 % & 66! 8 < .8. > : , 8 ? "# $# ' ' ' " $ $ $ 4 4 5 3 ' ' ' " " " $ $ 1 1 1 4 " " " " " $ 1 1 1 1 4 5 & # ! 1. Préambule 0 , 0 !; , )# @ & #& ,= ) B A , 0 >##<<< ) , , D * E C % % ! * B ? , ! , * & : % , ? ? , & . ) ,, F @ , G :H) , 2. A.N.F.A. !*%.- !I J 0 I%& ? , * & , ? ;<<< J0 & )= %& ? , ) ) 3. Définition ) 7 7 , 0 & - 0 ! ? ; ,, / + @ ,? , $ $F 8JJ. $4 & 9= F 5'" ; 7 ;) & , ) >##<<< & ? J0.# . & 8JJ. ;8@ J : J )# & # & $ $ , = & "# $# !* , ) = 4 ) & . ,, ? , = # ! 4. Apache 4.1. Origines % 7 55" % 7 ? B ( % & * ) , & ! A , 6 &< ) & & * : F& F I& , *% ,3 6 L? , ! & , & , ) , L 3 A * , ) && '' ? 1? & A & ) ? , ! & % ,, A , 555 ? 7 7 ? % , , % F ) ;$ K , = 06% ; 0 ) 7 >/ = , : ? , & %M ? L * ) , L ,) 4.2. Installation avec l’archive tgz % /usr/local/apache , ! ? F &) , , • • • • • • • • • • 6 J ; ? * ) G & * , % 9: , 0 , 6 - 1 ) , F *% & , ; : =F )+ )# < ) )+=F ; G ,, N+:&=F 1F > ./configure --prefix=/usr/local/apache ? F ,, ? & makeF ; =F ,, make installF , ) > ln –s /usr/local/apache/bin/apachectl /etc/init.d/httpdF • • , < ,, 6 service httpd start, F "# $# '# ! • J < ) 4 4 , - , ? > 7 % < ; >## , 1 >4 4 #F :@= & *% 4.3. Installation avec les rpms • • • • • 6 J 6 ) o o o o o o o o , o , & * ? * , F , *% >## ,& > I 1I , O "4$ , I ,, I 1I , O "4$ , I &I 1I , O "4$ , I, I 1I , O "4$ , I, I 1I , O "4$ , ; = I I 1I , O "4$ , ; =F I I$ 4$ , ; .8. =F G I I 4$ , ; . =F G I 4 I , O ,; 66! =F ) -./ ; : ? ; =F , > Rpm –ivh =F apache-1.3.27-2mdk.i586.rpm \ apache-common-1.3.27-1mdk.i586.rpm \ apache-conf-1.3.27-2mdk.i586.rpm \ apache-modules-1.3.27-1mdk.i586.rpm \ mod_perl-1.21-20.i386.rpm \ mod_ssl-2.8.12-1mdk.rpm "# $# "# ! • • • , < 6 J ,, < service httpd start, ) 4 4 , < ; >## F >4 4 #F :@= 1 & 4.4. Arborescence des fichiers en installation tgz /usr/local/apache/bin > |cgi-bin | |conf > |htdocs > |icons > A |include |libexec |logs > & |man > |proxy > : > & @ ,? ) de &) ) ,, 0 & < * 2 , & >& > < , ; ,, * : : , , , * ) * A ) * :@ ? ) = , 4.5. Arborescence des fichiers en installation RPM /etc/httpd/conf > &) /usr/bin > : /sbin > : /lib/apache > /share/man > , /share/doc > , /var/log/apache > & /www/ > racin /www/cgi-bin > * : % , A : < & , ) ,, & 0 @ ,? 8J/! ) ) 4.6. Configuration générale ! & , • • • • • ! ,, : ,, , ) , * &>& &>& @ > & F =F > & & : &>& & • • • &) "> , &) F & 2 @ >##<<<I ,, , I , * 3 : ) & #P Q#/ /9 * & < F ; , @ ,, @ : * & & , * & ; @ =F &) & ,, ? * & 0 A I * & : > (.J ( %!9 R690J ( ST R#690J ( S U ,, "# $# $# ! 9 , & & F &) B ) ,, service http reload ou service http restart ! ; >## &) >4 4 #= 1 0 < ? ? > & >4 4 > & ,, * . *% ! > > & , 0 , 0 4 , , > &> & , , ! B @ . * , . 0 ! > @ &> : , H .> . # ! < . . J0. ! ! J0. 0 , , ); = > @ @> ) * ? : U , ? !* ) ? @ > ,B, > ) ,G ># ># , # A & : # &) * $> %& ' > ) 7 & ? ? , < , * : % 0 && * 6G G W 0 &? : * ) > * ) & User web , , H ,G G > , ? ; F I V< V ? > B : = % 3 * )# ) )# # # # > , , 8 # >0 , >0 , O> & > , C C ! " 0 G )> & ) ;<<< , ,= O & < 0 , & 2 A 1 ) @ ) 9 & ) ,, ? ) & 9 * 3 @ 3 3 3 )F XF X ,, "# $# 1# ! &' > )# > C O ) ) , @ 3, , 3 *% * *% 0 & @ : &' > )# G ,, > && *% > ( O @ *% ) $># ( ! * & : # # > - ? # )# G ) ,, > ? B ! & , ) chemin_vers_le_fichier règle_de_formatage_des_traces & 3) ! ) @ 3, *% , & ,, & ) , && 4.7. Contrôle d’accès 4.7.1. Directives générales ! R ) , 3 @S ? *> ) & ;<<< , : : & ) , ,# ? & & * > + , • • • * & ,# , &? : & & F * ? B ,= 9 ? ) , & 2 & ? & , & & <F ,3 ; % > 3 , > <6@,! O > @, ? F 9: 0 > * : 0 F > @ 6 I6 I F (9L90 > , , 0 U F : > * ) & , @ : * ; / < >. , & ) & , I ? , & , , : = . F 6@, O &(< / > , <6@,! O , & & ,B, > * 9 &/ * > , F % > '' ,+ Y • • & && ,> * ) ? <<< , , 9 & • • • • • & B % > , = & , U : * & =F @ , 3 , ; ? & 7 ) 0 F ) F "# $# 4# ! • % &)> % Z ) % + ? , , & ; % Q/ F % Q/ F % % , F % J@ F % F - ? F , *% =F & > % Z ) 2 Z 3 : @ , ; % 9 )F % ! ) ) F % J@ F & J@ F 9 , ! ) ) . @F , *% =F : >. , & * : * && ) ) * :; % F% F% Q@9 )F % Q@J@ & F @ :F @ : )F 8 , F :) F :( - , , F , *% =F !, >% Z ) 2 3 2 ; <F @ = ( >% Z ) 2 & &? ; ) ( , % LQ 8 O= • • • • 0 > &' > , & & ? F F F F * 3 4.7.2. Directives d’authentification et de limitation des accès ! B & - , ? & & > * - % + @F % - ? R ? * @S * & , <& , % > ,=F <> > & F * 3 & ? & F W <F & F * ! W * W ? 0 & *% > : ? ) #, & , ) * & , * >Q !* ? < < , &) . % F ? ? F @ * & ) @ < , @ ! > & B , ;% < ? @ % I ? * < > * 3 @ ? % <F @> * 3 < ? W / I& > • ,, ? @F % • @S 3 ? '' ," & , , • R > & / " 9 & , Q 3) ) * ,3 * ? * * & * ? ) 0 , ) ) , & ! ) F * $' Q "# $# W * ) Q * && & ) 5# ! &' ># # G >& 0 & % ? = ! & B ! ) ! ) >, >, ? , @ : ! ) ,, & > G @ G @ &' > # ? # G) > & && ? ) ! ) ! & & , < ; , B B % & @ : ! > > > / > • - ? ! - ? • - ? I F - ? & I < @ 3, ,B, - ? & I) • ) & 0 > F %A > * ) B > ,& I < & B & & , F ) ) ,, * < ) @ 3, ; > htpasswd –c /etc/apache_users username > , , , , #, > A * ! & & * * 2 , > & ; : * & > htpasswd /etc/apache_users , = , ) , * : , > => * 6 * : & & username • ) > G • @ & ) % • && > F ) • • ! * & ? 3 : 4.8. Multihoming 4.8.1. Directives de configuration ! , , ) ) ,B, ) ! > ' J >% # ? B , G G >##<<< , G& ,# > , & ) "# $# , G G * G& # ! >6 J ' ? )3 % , 0 '1 , * & 0 !* , '1 . , ) > 2) B , , ,[ ? B , 9 & , < A O 8 , ,> , , & , , ) &) , 1 [ ! "0 , '1 >4 > , * . ! & , , ) > & 8 ) J0. * , , ) ) . * * [ . ; = 3 ) > 3 &) ) . ,3 4.8.2. Multihoming par arborescence ! && ) ,B, . ,B, &) 0 * 3 R , , && &? )3 2 & @S &> Alias /site1 /meswebs/site1 Alias /site2 /meswebs/site2 Alias /site3 /home/user_site3 4.8.3. Multihoming par adresse IP ou par port ! && && . # ! 8 Listen 192.168.1.1 :80 Listen 192.168.1.1 :443 Listen 192.168.1.2 :80 <VirtualHost 192.168.1.1:80> ServerName www.mondomaine.com DocumentRoot /mesweb/mondomaine.com </VirtualHost> <VirtualHost 192.168.1.1:443> ServerName www.mondomaine.com DocumentRoot /mesweb/mondomaine_secure.com </VirtualHost> <VirtualHost 192.168.1.2:80> ServerName www.trucmuche.com DocumentRoot /mesweb/tructmuche.com </VirtualHost> ! > • ! #, < <<< , #, , , ,F , * "# $# 5 $4 F & # ! • • ! #, < ! & % # > <<< , , , , <<< , , , #, < #, , , ? 6 * * G 5 $4 5 $4 F & 66! ; '' =F , , B 6 4.8.4. Multihoming par nom ! && ) ,B, &) & . ) ,B, , && , , 8 & & 8 NameVirtualHost * <VirtualHost *> ServerName www.mondomaine.com DocumentRoot /mesweb/mondomaine.com </VirtualHost> <VirtualHost *> ServerName www.tructmuche.com DocumentRoot /mesweb/trucmuche.com </VirtualHost> <VirtualHost *> ServerName www.bazar.com ServerAlias bazaar.com *.bazar.com DocumentRoot /mesweb/bazar.com </VirtualHost> ! > • • • ! #, < ! #, < J % # > - , ? <<< , , , ,F <<< , , ,F [ + , #, , > ? , , : 3 3 6 , 3 & : & :& , #, < # + B & ) , 6 * F , 8 4.9. Configuration avancée 4.9.1. Directives 1 % > & ) 6 && > , & ? * 6 && ? * ? A , & , & . 0 ) 3 ? ? * * 3 & ; , =F "# $# # ! > 4 * > & , ! ? * @ ? B >"> 4 * & , & & , ? ? B , , & : F A ? * ? ? B 4 *(' > "$ > , , :, , , 4 * % > 4 *5 ,B, ' > : % / * F )64 * ' 8JJ. & , , :, , , , , ! ) / / G , > ! , ! ")64 ? > ' > & ! , G * (' % , * % , ) : #, , , G , 4 F , ? B ? : # > ! ? B & * , :, , G , & 9: , B ! , ? & , * , , ' 7 , * % J0. & ? ,B, ? B ? * 0 , & ! ! / * A *% ' >% / ) , 4 > \ : & ' > ! 4 @ ,? > , 3 , , / \ % ? B , :, , ) > > + % , , , 5 ' ? B . * , :, , & ? ( ' > / & Y , ! , ) ; , , ' & &) 4.9.2. Répertoires utilisateurs • • • , % & , I > AddModule mod_userdir.c ? C G O ) , > RIfModule mod_userdir.c> UserDir public_html </IfModule> ! ? B P >##<<< , G , # ,#P # 3 : & O 4.9.3. Compilation avancée ! * , ;# &) =F B > 88 6 *9" "' '" > , & C "# $# % ] # ! ' 9 ' 7 > 88 ' 8 @ ,? ] 9 ' 7 > 88 ' 9 88 ' 8 8 88 ' 8 88 * ' 8 * 8 ' 9 , > 3) * % * ) ,, ) & , , > ; ] , 8' 8 ' 7 > * : * , : & ? = :F , ] *% ] % ) 4.10. Sécurisation ? F 4.10.1. ! , * * @ 3, ! , , * ) : A F = ) ? ) & ; B ? Modules à désactiver ) , , * , F, : * F & , :, , –-disable-module –-disable-module=all ? , , , @ * , ? , & & ? ; B @ 3, ; 7 => • • • , , , G G < G • • • • • • , , , , , , G G G ) G G G, & <<< ) , = : * -! * -! & ) 6 6 ;66 = 0 ,, < @ & ;0 = ; 0 & , ) ^ * & , * , ) ? 2 , , & , 7 & ; ; : = & * % , ; + .8.= ,= ? )= 4.10.2. Droits sur les fichiers % * :& ) * ? * F ? % ) * & 3 * , * ? F & & * ? ? : , ,B, & Y ) 7 % ; , ? * F * : ? ? B : , )F # ) ) "# $# 7 I < = * B : '# ! ! * * ? ) : 3 *% ; ! , # : % = B % & F , * : *% * : , & ,, + F & * ? 3 I < F * % <III:II: , F mkdir /usr/local/apache cd /usr/local/apache mkdir bin conf logs chown 0 . bin conf logs chgrp 0 . bin conf logs chmod 755 . bin conf logs #Suivez la procédure d’installation chown 0 /usr/local/apache/bin/httpd chgrp 0 /usr/local/apache/bin/httpd chmod 511 /usr/local/apache/bin/httpd 4.10.3. 6 & : ? , & Options sur le site Web F ? , ,3 & & ? &? + & * ? ) 3 ) & % , <( &) & B ? > <Directory /> AllowOverride None Order Deny,Allow Deny from all </Directory> . :& @ 3, ; ? # # < = <Directory /usr/local/apache/htdocs> AllowOverride None Order Deny,Allow Allow from all </Directory> / < ! 6 : F 6 * @ O B : & , *B ) ? ) C F & 2 * : F & , , , CGIs 7 ? & 3 0 , ) Support de l’authentification 4.10.5. 0* < @, & + * 4.10.4. ! & @ ,? , 3, 3 B "# $# "# ! 6 F & + ) ,, 3) , : , 2 , ,3 && && I 6 6 ;0 & < ) = 6 F , ) + ? * : ? 4.10.6. 6 ? * * , ? 2 Mettez en place le support de SSL + 66! * @ : ) 7 A 4.10.7. , , Utilisez mod_security G @F % , 2 & & * ? • • , , % + 0 &) • ;<<< , * , @ )= AddModule mod_security.c ; & > <IfModule mod_security.c> AddHandler application/x-httpd-php .php SecAuditEngine On SecAuditLog logs/audit_log SecFilterScanPOST On SecFilterEngine On </IfModule> • + R# &/ S ) , & * ? 066 > SecFilterDefaultAction "deny,log,status:500" "<(.|\n)+>" SecFilter 0 * ? * : , &) F A : , G @ * & , A 4.10.8. * * + Logs * , & 3) O ) F * ) @ 0 :I + 4.10.9. ! ) ! : * , • 0 • 0 *% : ! & @ 3, + * : Chroot , ) ? *% % , * , 0 , , 3 ? * : & * & * ; * : # # ) @ 3, = > ,O *% < @ 3, * # #< @ 3, > "# $# $# ! cd /chroots/web mkdir bin dev etc sbin tmp usr var usr/lib usr/share usr/share/local usr/share/zoneinfo chmod +rwxogu tmp chmod +t tmp • 0 & , , ? F A & *% , + ; N => ,, , F & #création d’un device /dev/null mknod –m 666 dev/null c 1 3 #paramétrage de la zone cp –pi /usr/share/zoneinfo/[VOTREZONE] usr/share/zoneinfo cd etc #paramétrage de l’heure ln –s ../usr/share/zoneinfo/[VOTREZONE] localtime cd .. cp –a /usr/share/locale/[VOTRELOCALE] usr/share/locale #copie de quelques libs utiles cp -pi /lib/libtermcap.so.2 /lib/ld-linux.so.2 /lib/libc.so.6 lib/ #copie d’un shell cp -pi /bin/sh /bin/cat bin/ #création des fichiers d’utilisateurs touch etc/passwd etc/group etc/shadow chmod 400 etc/shadow #creation d’un utilisateur pour l’exécution d’Apache (aucun utilisateur root ne sera créé) echo 'www:x:888:888:Web Account:/webhome:/usr/bin/false' > etc/passwd echo 'www:x:888:' > etc/group echo 'www:*:10882:-1:99999:-1:-1:-1:134537804' > etc/shadow cp –pi /bin/false bin #les fichiers binaires sont en exécution seule chmod 111 bin/* chmod 111 usr/local/apache/bin/* #libs nécessaires au DNS cp -pi /lib/libnss_files.so.2 lib/ cp -pi /lib/libnss_dns.so.2 lib/ • 0 &) # 6F < + & > & passwd: files shadow: files group: files hosts: files dns # & domain mondomaine.com # adresse du DNS (ici un cache local) nameserver 127.0.0.1 # 127.0.0.1 localhost loopback #adresse IP interne du serveur 192.168.196.2 ns.mondomaine.com ns www • 0 & *% > Cp –pi /usr/local/apache usr/local/apache #quelques libs nécessaires au fonctionnement d’Apache cp -pi /lib/libdl.so.2 /lib/libm.so.6 /lib/libcrypt.so.1 /lib/libdb.so.3 lib/ cp -pi lib/ • 7 0 7 > /messites/webF & & ? ? /chroots/web/messites/web "# $# 1# ! • , #< # # % # * , ; ? *% = > chroot /chroots/web /usr/local/apache/bin/apachectl # start 6 O # . • + .8. # , #,@ ? O , + #< # • F ,@6M! + : 3, 6 # ,@6M! 6 # @ ? # , #,@ ? O ? + &) ,@6M! .8. F &) * .8. & * : * , > # , #,@ ? O & ? ,@6M! , ,B, > # @ ? F # , #,@ ? O ,@6M! . ; . & ? < = - , ? > &) F & ) * , & ; ? , & ? *% 9 = B ? ? , 3? F , + "# $# 4# ! 5. Sécurité avec SSL 5.1. Installation de modssl & * O ) ( & , • • • • • 6 J ) <<< 66! & & , 66! ; , G , I 4 I )= G ;<<< , 1 )+ )= <<< , ) & ) *% % , G ; # , = > cd mod_ssl-2.8.12-1.3.27 • 0 &) , G > ./configure --with-apache=../apache_1.3.27 --with-ssl=chemin_openssl \ --with-crt=/usr/local/apache/conf/ssl.crt/server.crt \ --with-key=/usr/local/apache/conf/ssl.key/server.key \ --prefix=/usr/local/apache • . * - , ? <<< , > *% ,, * , , ) 5.2. Configuration du serveur & & 66! &) &) *% 66! ; ) . : , F , 66! % &) & : = AddType application/x-x509-ca-cert .crt AddType application/x-pkcs7-crl .crl 0 ) , & % 3) 4 , ( 66! > ( . ,, ? 7 , ) *% ,># # # > % !* C > 66! # '> & ; ? # )# G ? >& , & # 66!= & > & ) O &) ;66!- : G ) C O Q B # )# C > > @ 0 = = * , * > file:/usr/local/apache/logs/ssl_mutex : & , ? 3) 3 66! $ > V# , $ > & ( ,6 ;66!- & 66! ' $> ? W G )V > & A , "# $# A ) , ,6 , 66! ;& ) = *% , 66! 5# ! ! &? 8 > # $ > ? ? ) &? 66! J 66! 3 66! : &' > # # ( 66 ( 6 5 &' > # ( , 3 6 ( & ( ( *% ( ( & ' ># 6 0 ( & !* &# # # # # 8>`/9 />`!(7>`66! >`9L.>` # >& O @# O @ > & &# # &# ? > > , 66! & ? & & ? * W 3 & )3 # & # # # ? &# # &' > # & # # ># 6 0 )3 # B J0. '' & > %!!>_% 8>_9L."$>-0'`-6%>`8 @ ) ( !! > *% < # ? )3 ># , # # &# # # ,, # &# > & > ? & , ) / ? & > SetEnvIf User-Agent ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 5.3. Configuration des répertoires !* &) & & . & > / ? * 0 * 6 (' & > 66! > , > 66! * 3 66! * 0 > ? & , ( - ? : # ? > , 2 ? * ) & ? * ;? ) * * * & * , 0% = + • • > `6 9 ; `6 9 0 `6 - ? , > , => : > & & & * * & , , ? ,, 66! ! ? : 66! 2 * "# $# 66! ? 66!- ? 66! # ! • ` O Q % > , & & 2 * 3 . F & A & % * , , , % a H , ,V ! , / & & : , > Kb66!G0! 9 JG6G ? * & B G0 c 66! Q 2 * * 3 ) & V0 a * bV Vc > , & 66! % ; = & ! , #(a/ 0%#( a/ # B V < V & * : , F 0 ,, , : "# $# # ! 6. Intégration PHP ! 3 • • • • • ) , 6 J & , @ ,? 3 .8. ; <<< = B > ) * 3 ) .8. * * , . <<< ) .8. ./configure --with-apache=../${SRC_APACHE} --with-mysql=/usr/ • • • • • • • , : ,@ ? -./ ) 0 , 6 , B ) .8. ? ? /@6M! * & , ; .8. –with-mysql=/usr = ,, .8. % ,, .8. > , * ) , O , O % > , & & & A o LoadModule php4_module libexec/libphp4.so > ) 3? .8. o AddModule mod_php4.c > , IfModule mod_mime.cF A VAddType application/x-httpdo php .php .php3 .php4V ? &) /, & .8. 6 I 0 &) * .8. , 0 > <Directory /monsiteweb/scriptsphp> #Directives générales DirectoryIndex index.php index.php3 #charge par défaut la page index.php <IfModule mod_php4.c> #configuration spécifique au module PHP php_value include_path '/usr/local/lib/php:.' # répertoires dans lesquels sont stockés des bilbiothèques de scripts php php_flag magic_quotes_gpc Off #pour la sécurité php_flag track_vars On #pour la sécurité </IfModule> </Directory> • J < ? .8. ; & : , : = 7. Documentation • • • • • • • • • • ' - ,,,: : $ 6 ) , , > >##<<< , - 0 > >##<<< & ? )# & # .8. > <<< ( 66! > <<< ) / 66! > <<< , ) /, > >##<<<I , I ) & #P Q#/ /9 , , & Y > >## 5 :& , @ )# :# : 'd ) a , !%/. > >##<<< :& )# # , # / G @> >##<<< , @ ) "# $# 1 , # ! 8. Contrôle de l’intégrité des sources 8.1. Avec PGP • • J J ) ) & . . *% ) ; F >##<<< I )# # #\9e6 = 1> -----BEGIN PGP SIGNATURE----Version: PGP 6.5.1i iQA/AwUAPZrvg4s6YB8IyXXlEQKkpgCeOxSBEXlgyuzEwf6MlZD/5+sjrPcAoNn6 q7jvnn1yVfN4T3JOoy2Xm9Zg =JeQp -----END PGP SIGNATURE----- • & ) > & ,B, ? C + % pgpk -a KEYS % pgpv apache_1.3.27.tar.gz.asc % pgp -ka KEYS % pgp apache_1.3.27.tar.gz.asc % gpg --import KEYS % gpg --verify apache_1.3.27.tar.gz.asc 8.2. Avec MD5 • • 9: 0 , ,, 1> $" 45 $" $" % md5sum apache_1.3.27.tar.gz * 1 '' 0 I '4$ "# $# # ! 9. Script de compilation d’apache avec php et modssl ! ; I , = .8. F , ,@ ? ;? , ) F B F & B % , , , G G < G • • • • • • , , , , , , G G G ) G G G, @ , = ; @ =F + F A )F , , @ ,? & * -! * -! & , ) ; , @ 3, ; = : ) = , • • • ? * ) 6 6 ;66 = 0 ,, < @ & ;0 = 0 & , ) ^ * & , * , ) ? 2 ; 7 : = * % #!/bin/sh #repertoires ou telecharger les sources #www.openssl.org #www.modssl.org #www.apache.org #ftp://ftp.cac.washington.edu/mail/ #www.php.net BUILD_OPENSSL=1 CONFIG_MODSSL=1 CONFIG_APACHE=1 BUILD_IMAP=1 BUILD_PHP=1 BUILD_APACHE=1 SRC_APACHE=apache_1.3.27 SRC_OPENSSL=openssl-0.9.7 SRC_MODSSL=mod_ssl-2.8.12-1.3.27 SRC_IMAP=imap-2002 SRC_PHP=php-4.3.0 DST_APACHE=/usr/local/apache DST_OPENSSL=/usr/local/ssl DST_MODSSL=mod_ssl-2.8.8-1.3.24 DST_IMAP=imap-2002 DST_PHP=php-4.2.1 APACHE_DISABLED_MODULES=--disable-module=proxy \ --disable-module=mod_alias \ --disable-module=mod_rewrite \ --disable-module=mod_userdir \ --disable-module=mod_autoindex \ --disable-module=mod_include \ --disable-module=mod_status \ --disable-module=mod_imap "# $# '# ! if [ ! -d ./Logs ]; then mkdir ./Logs fi if [ $BUILD_OPENSSL -eq 1 ]; then echo Openssl cd ${SRC_OPENSSL} echo " Config" ./config --prefix=${DST_OPENSSL} shared >& ../Logs/openssl_config.log || exit 1 echo " Fin : Config" echo " Compil" ; make >& ../Logs/openssl_compil.log || exit 1 echo " Fin : Compil" echo " Install" ; make install >& ../Logs/openssl_install.log || exit 1 echo " Fin : Install" echo "Openssl fin" cd .. else echo Openssl : ignore fi if [ $CONFIG_MODSSL -eq 1 ]; then echo mod_ssl cd ${SRC_MODSSL} echo " Config" ./configure --with-apache=../${SRC_APACHE} \ --with-ssl=${DST_OPENSSL} \ --with-crt=${DST_APACHE}/conf/ssl.crt/server.crt \ --with-key=${DST_APACHE}/conf/ssl.key/server.key \ --prefix=${DST_APACHE} >& ../Logs/modssl_config.log || exit 1 echo " Fin : Config" echo "mod_ssl fin" cd .. else echo mod_ssl : ignore fi if [ $CONFIG_APACHE -eq 1 ]; then echo "Apache (preparation)" cd ${SRC_APACHE} echo " Config" ./configure --prefix=${DST_APACHE} >& ../Logs/apache.log || exit 1 echo " Fin : Config" echo "Apache fin" cd .. else echo "Apache (preparation) : ignore" fi if [ $BUILD_IMAP -eq 1 ]; then echo imap cd ${SRC_IMAP} echo " Compil" make slx >& ../Logs/imap-compil.log || exit 1 echo " Fin : Compil" echo "imap fin" cd .. else echo imap : ignore fi if [ $BUILD_PHP -eq 1 ]; then echo PHP cd ${SRC_PHP} "# $# "# ! CFLAGS='-O2 -I${DST_OPENSSL}/include' echo " Config" ./configure --with-apache=../${SRC_APACHE} \ --with-gettext \ --with-freetype-dir \ --with-mysql=/usr/ \ --enable-memory-limit=yes \ --with-imap=../${SRC_IMAP} \ --with-zlib-dir=/usr \ --with-jpeg-dir \ --with-png-dir \ --with-gd >& ../Logs/php_config.log || exit 1 echo " Fin : Config" echo " Compil" ; make >& ../Logs/php_compil.log || exit 1 echo " Fin : Compil" echo " Install" ; make install >& ../Logs/php_install.log || exit 1 echo " Fin : Install" echo PHP fin cd .. else echo PHP : ignore fi if [ $BUILD_APACHE -eq 1 ]; then echo Apache cd ${SRC_APACHE} SSL_BASE=${DST_OPENSSL}/include/ EAPI_MM=../mm-1.1.x echo " Config" ./configure --enable-module=ssl \ --enable-shared=ssl \ --prefix=${DST_APACHE} \ --activate-module=src/modules/php4/libphp4.a \ --enable-shared=php4 \ ${APACHE_DISABLES_MODULES} >& ../Logs/apache_config.log || (exit 1) echo " Fin : Config" echo " Compil" ; make >& ../Logs/apache_compil.log || exit 1 echo " Fin : Compil" echo " Install" ; make install >& ../Logs/apache_install.log || exit 1 echo " Fin : Install" echo "Apache fin" echo Fin cd .. else echo Apache : ignore fi "# $# $# ! 10. Exemple de configuration d’une restriction d’accès 10.1. Fichiers AuthUserFile et AuthGroupFile . : , 10.1.1. ! ! , F & & > AuthUserFile (/etc/htpasswd) @ , V#0a -#6Ja1"TV : , 66!= ; * LLL & 66! joe:XXX bob:XXX alice:XXX /C=FR/ST=75/O=Maison/OU=Maison Users/CN=homme/[email protected]:XXX /C=FR/ST=75/O=Maison/OU=Maison Users/CN=femme/[email protected]:XXX root:XXX 10.1.2. AuthGroupFile (/etc/htgroups) Utilisateurs_ssl: "/C=FR/ST=75/O=Maison/OU=Maison Users/CN=homme/emailAddress=ho [email protected]" "/C=FR/ST=75/O=Maison/OU=Maison Users/CN=femme/emailAddress=femme@ home.com" Utilisateurs_web1: "/C=FR/ST=75/O=Maison/OU=Maison Users/CN=homme/emailAddress=h [email protected]" alice joe Utilisateurs_misc: joe bob 10.2. Globalement dans access.conf - * 3 A > <Directory /usr/local/apache/htdocs/secure> AllowOverride None DirectoryIndex index.htm Order allow,deny Allow from all AuthName "Acces restreint" AuthType Basic AuthUserFile /etc/htpasswd require user joe bob alice </Directory> ! @ : ,B, <Directory /usr/local/apache/htdocs/secure> AllowOverride None DirectoryIndex index.htm Order allow,deny Allow from all AuthName "Acces restreint" AuthType Basic AuthUserFile /etc/htpasswd AuthGroupFile /etc/htgroups require user alice require group Utilisateurs_misc </Directory> ! @ : , < "# $# > 1# ! <Directory /usr/local/apache/htdocs/secure> AllowOverride None DirectoryIndex index.htm Order allow,deny Allow from all AuthName "Acces restreint" AuthType Basic AuthUserFile /etc/htpasswd require valid-user </Directory> 9 & @ : , * & ; = <Directory /usr/local/apache/htdocs/secure> AllowOverride AuthConfig # activation du support de fichier htaccess DirectoryIndex index.htm Order allow,deny Allow from all #il est possible de definir un controle d’acces qui pourra etre modifier par un fichier htaccess s’il existe </Directory> 10.3. Locale via un fichier .htaccess 0 C . & ,B, > ? & : , & , A F > Order allow,deny Allow from all AuthName "Acces restreint" AuthType Basic AuthUserFile /etc/htpasswd AuthGroupFile /etc/htgroups require group Utilisateurs_misc "# $# 4# ! 11. Exemple de configuration SSL 11.1. Httpd.conf ? * & ? * & ) = <IfDefine SSL> AddType application/x-x509-ca-cert .crt AddType application/x-pkcs7-crl .crl </IfDefine> <IfModule mod_ssl.c> SSLPassPhraseDialog builtin SSLSessionCache dbm:/usr/local/apache/logs/ssl_scache SSLSessionCacheTimeout 300 SSLMutex file:/usr/local/apache/logs/ssl_mutex SSLRandomSeed startup builtin SSLRandomSeed connect builtin SSLLog /usr/local/apache/logs/ssl_engine_log SSLLogLevel info </IfModule> <IfDefine SSL> Listen 443 <VirtualHost *:443> DocumentRoot "/usr/local/htdocs" ServerName www.mondomaine.com ServerAdmin [email protected] ErrorLog /usr/local/apache/logs/www_ssl_error_log TransferLog /usr/local/apache/logs/www_ssl_access_log SSLEngine on SSLCipherSuite ALL:!ADH:!EXP56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL SSLCertificateFile /usr/local/apache/conf/ssl.crt/www.mondomaine.com.crt SSLCertificateKeyFile /usr/local/apache/conf/ssl.key/www.mondomaine.com.key SSLCertificateChainFile /usr/local/apache/conf/ssl.crt/ca.crt SSLCACertificatePath /usr/local/apache/conf/ssl.crt SSLCACertificateFile /usr/local/apache/conf/ssl.crt/ca.crt SSLCARevocationPath /usr/local/apache/conf/ssl.crl <Files ~ "\.(cgi|shtml|phtml|php|php3?)$"> SSLOptions +StdEnvVars </Files> SetEnvIf User-Agent ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 CustomLog /usr/local/apache/logs/ssl_request_log \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" </VirtualHost> </IfDefine> 11.2. Access.conf 11.2.1. Authentification SSL avec contrôle d’accès dans des fichiers .htaccess <Directory /usr/local/apache/htdocs/secure AllowOverride AuthConfig DirectoryIndex index.htm Order allow,deny "# $# 5# ! Allow from all <IfDefine SSL> SSLRequireSSL SSLVerifyClient optional # il est possible de se connecter sans certificats pour de simples utilisateurs declares dans htacccess par exemple SSLOptions +StdEnvVars +StrictRequire +FakeBasicAuth </IfDefine> </Directory> & & % A & ) > CN=root/O=MaCA/OU=Maison/[email protected]:xxj31ZMTZzkVA ! % ::A && f/Jf+O % , * 3 D & < ,, E @ & > Order allow,deny Allow from all AuthName "Acces restreint" AuthType Basic AuthUserFile /etc/htpasswd require user "CN=root/O=MaCA/OU=Maison/[email protected]" 11.2.2. Authentification SSL avec contraintes * . & 3 * ) & 0% F ` O Q 7 % * , * <Directory /usr/local/apache/htdocs/secure> AllowOverride None DirectoryIndex index.php # pages dynamiques générées par PHP Order allow,deny Allow from all <IfModule mod_php4.c> # configuration de PHP php_value include_path '/usr/local/lib/php:.' php_flag magic_quotes_gpc Off php_flag track_vars On </IfModule> <IfDefine SSL> SSLRequireSSL SSLVerifyClient require # il n’est pas possible de se connecter sans certificat SSLOptions +StdEnvVars +StrictRequire SSLRequire %{SSL_CLIENT_S_DN_CN} in {"root"} # le Common Name doit être root </IfDefine> </Directory> "# $# # ! 12. Helloworld PHP : index.html <html> <head> <title>Exemple</title> </head> <body> <?php write "Bonjour, je suis un script PHP!" ?> </body> </html> "# $# # ! 13. Historique des version • F '# # >. ,3 • F # > • F '# $# # ! , >/ G & * : @F "# $# #