/etc/httpd/conf/httpd.conf
Listen 80 #default
DocumentRoot "/var/www/html" <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory>
TransferLog logs/access_log ErrorLog logs/error_log # Possible values include: debug, info, notice, warn, error, crit, alert, emerg. LogLevel warn
KeepAlive On #default: Off KeepAliveTimeout 15 #default: 15
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" ## This controls which directories contain server scripts. AddHandler cgi-script .cgi ## Enable CGI execution of script with extention .cgi # AddHandler cgi-script .cgi .bash ## Enable CGI execution of script with extention .cgi or .bash
AddHandler php5-script .php # Cause the PHP interpreter to handle files with a .php extension
Modello di dafault (multiprocesso): Apache MPM prefork
How to get the threads per process:
#ps -uapache -opid,ppid,nlwp PID PPID NLWP 28332 28330 1 28333 28330 1 28334 28330 1 28335 28330 1 28336 28330 1 28337 28330 1 28338 28330 1 28339 28330 1
Modello opzionale (misto, con N thread per processo): Apache MPM Worker
Per attivarlo scommentare HTTPD in /etc/sysconfig/httpd:
# The default processing model (MPM) is the process-based # 'prefork' model. A thread-based model, 'worker', is also # available, but does not work with some modules (such as PHP). HTTPD=/usr/sbin/httpd.worker
Per verificare:
# ps -uapache -opid,ppid,nlwp PID PPID NLWP 10622 10604 27 10654 10604 27
# Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf
/etc/httpd/conf.d/userd.conf
UserDir html # Enable user's documents in html subdir <Directory /home/didattica/*/html > AllowOverride FileInfo AuthConfig Limit Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec ExecCGI </Directory> RedirectMatch /home/(.*) /~$1
Il firewall di lpr-bastion e' stato configurato in modalita' NAT per le connessioni entranti in modo che le richieste a lpr-bastion.fis.unipr.it:80XX vengano girate nella LAN interna con destinazione 192.168.1.XX:80XX :
iptables -t nat -A PREROUTING -p tcp -i eth0 -d 160.78.35.98 --dport 80XX -j DNAT --to-destination 192.168.1.XX
Per vedere queste configurazioni su lpr-bastion: iptables -nvL -t nat
L'opzione –line-numbers mostra il numero univoco di ogni regola: iptables -nvL -t nat –line-numbers
/etc/httpd/conf.d/vhXX.conf
Listen 80xx <VirtualHost 192.168.1.xx:80xx> DocumentRoot /home/didattica/<USER>/html/RETI1516/www/ ServerName cognome.lpr.fis.unipr.it ErrorLog /home/didattica/<USER>/html/RETI1516/www/error_log TransferLog /home/didattica/<USER>/html/RETI1516/www/access_log <Directory /home/didattica/*/html> Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec +ExecCGI AllowOverride FileInfo AuthConfig Limit </Directory> AddHandler cgi-script .cgi .bash ## Enable CGI execution of script with extention .cgi or .bash </VirtualHost>
Documentation: Options - AllowOverride
Accesso:
http://lpr-bastion.fis.unipr.it:80XX/
Autenticazione e autorizzazione di Apache
Il controllo avviene mediante opportune direttive di accesso che consentono il controllo basato su
Esempio di configurazione in /etc/httpd/conf.d/ :
<Directory /home/didattica/<USER>/html/RETI1617/www/priv/ > order deny,allow #allow from all #allow from .unipr.it allow from 160.78. deny from all </directory>
Le direttive di autenticazione e autorizzazione possono essere incluse nella directory da controllare mediante il file .htaccess
Questa delega deve essere autorizzata dall'amministratore mediante la direttiva
AllowOverride AuthConfig
Esistono diversi moduli che consentono di gestire diverse tecniche di autenticazione, tra cui:
http://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html
Il seguente esempio puo' essere inserito nel file di configurazione all'interno di direttive <Directory>..</directory> oppure nel file .htaccess.
AuthName "Pagina riservata" AuthType Basic AuthBasicProvider file AuthUserFile /home/didattica/<USER>/html/RETI1516/www/priv/htpasswd Require valid-user # accetta qualunque utente autenticato #Require user user1, user2 # accetta solo user1 e user2
In questo esempio il Backend di autenticazione e' un file di testo che contiene user/password, gestito dal comando htpasswd.
Nota: Per motivi di sicurezza il file htpasswd dovrebbe essere posizionato in una directory non pubblicata dal server Web.
Per verificare il funzionamento provare i seguenti comandi che codificano la password utilizzando vari algoritmi di cifratura:
htpasswd -n -b -d myName myPassword # crypt htpasswd -n -b -m myName myPassword # MD5 htpasswd -n -b -s myName myPassword # SHA #-n scrive l'output su stdout #-b modalita' background. La password non viene chiesta interattivamente ma viene specificata nel comando
Altre info: http://read.melodycode.com/tutorials/18/autenticazione_e_autorizzazione_usando_htaccess_di_apache.html
Scrivere le credenziali in un file:
htpasswd -c -m /home/didattica/<USER>/html/RETI1617/www/priv/htpasswd guest #-c solo la prima volta per creare il file htpasswd -m /home/didattica/<USER>/html/RETI1617/www/priv/htpasswd alfieri
yum install mod_authz_ldap
Cos'e' LDAP
Con il seguente file .htaccess viene richiesta l'autenticazione LDAP assieme al filtro basato sul dominio del client. Per accedere al documento basta soddisfare uno dei 2 metodi ( Satisfy any ).
AuthName "LDAP Authentication" AuthType Basic AuthBasicProvider ldap # AuthLDAPURL ldap://didattica.fis.unipr.it/ou=Users,ou=lpr,dc=fis,dc=unipr,dc=it?mail?sub?(objectClass=*) AuthLDAPURL ldap://didattica.fis.unipr.it/ou=Users,ou=lpr,dc=fis,dc=unipr,dc=it?uid?sub?(objectClass=*) AuthLDAPBindDN cn=browser,dc=fis,dc=unipr,dc=it AuthLDAPBindPassword browzer56 AuthName "Reti di Calcolatori - Netlab cluster (Studenti: <username> e password di Appost@PerTe)" require valid-user #require user username Satisfy any order deny,allow #allow from all #allow from .unipr.it deny from all
Alcuni riferimenti:
https://www.cloud.it/tutorial/come-installare-un-web-server-nginx-su-ubuntu-18-04.aspx
Installazione: apt install nginx Configurazione generale: /etc/nginx/nginx.conf Configurazione default server: /etc/nginx/site-enabled/default Root directory: /var/www/html/ Logs: /var/log/nginx/
Esercizi: https://techexpert.tips/it/nginx-it/
telnet localhost 80
GET /test.txt HTTP/1.0 <cr> HEAD /test.txt HTTP/1.0 <cr> GET /test.txt HTTP/1.0 If-Modified-Since: Mon, 06 Jan 2020 17:00:00 GMT <cr> HTTP/1.1 304 Not Modified ... GET /test.txt HTTP/1.0 Connection: Keep-Alive <cr> GET /test.txt HTTP/1.1 host: didattica-linux.unipr.it <cr> GET /test.txt HTTP/1.1 host: didattica-linux.unipr.it Connection: close <cr>
http://www.apacheweek.com/features/http11
telnet proxy.unipr.it 8080 ## PROXY GET http://netlab.fis.unipr.it/test.txt HTTP/1.0 <cr>
Client Linux a linea di comando per il trasferimento di documenti Web sono
Alcuni esempi:
wget -v http://netlab.fis.unipr.it/test.txt export http_proxy=http://proxy.unipr.it:8080/ wget -v http://netlab.fis.unipr.it/test.txt
Curl examples: http://www.thegeekstuff.com/2012/04/curl-examples/
client in PHP (HTTP-1.0 e HTTP-1.1)
Per la programmazione di una connessione HTTP non e' necessario scendere a livello dei socket, ma si puo' programmare con un maggiore livello di astrazione. HTTPlib in Python - esempi
Server in PHP (HTTP-1.0 e HTTP-1.1)
Python: Basic HTTP server - Simple HTTP server - PYmotw - esempi PyMOTW - esempi
superglob.php - esegui ( http://php.net/manual/en/language.variables.superglobals.php )
cookie1.php - esegui ( http://php.net/manual/en/function.setcookie.php )
session.php - esegui ( http://it1.php.net/manual/en/book.session.php )