127.0.0.1 localhost
127.0.0.1 test-site
127.0.1.1 my-hostname
# The following lines are desirable for IPv6 capable hosts. etc...
Dov'è test-siteil secondo "localhost". Ed my-hostnameè il "Nome host di sistema" definito in /etc/hostname.
2. È necessario definire e abilitare un host virtuale (VH):
C'è un VH HTTP predefinito. È inserito /etc/apache2/sites-available/. Il nome del file è 000-default.conf. Devi modificarlo (puoi rinominarlo, se vuoi, o creare altri file .conf, basati su di esso) e dopo devi abilitarlo.
È possibile abilitarlo manualmente attraverso la creazione di "link simbolico e soft":
sudo ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/
Oppure puoi usare lo strumento Apache2 chiamato a2ensite , che fa lo stesso:
sudo a2ensite 000-default.conf
Supponiamo che ci siano 3 host virtuali , SSL abilitato e dominio privato registrato (SOS.info per un esempio):
/etc/apache2/sites-available/http.SOS.info.conf
/etc/apache2/sites-available/https.SOS.info.conf
E uno che è stato creato ai fini di questo argomento:
/etc/apache2/sites-available/http.test-site.conf
Il contenuto dei primi 2 VH è:
$ cat /etc/apache2/sites-available/http.SOS.info.conf
<VirtualHost *:80>
ServerName SOS.info
ServerAlias www.SOS.info
ServerAdmin admin@SOS.info
# Redirect Requests to SSL
Redirect permanent "/" "https://SOS.info/"
ErrorLog ${APACHE_LOG_DIR}/http.SOS.info.error.log
CustomLog ${APACHE_LOG_DIR}/http.SOS.info.access.log combined
</VirtualHost>
Questo reindirizza tutte le richieste HTTP a HTTPS.
$ cat /etc/apache2/sites-available/https.SOS.info.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName SOS.info
ServerAlias www.SOS.info
ServerAdmin admin@SOS.info
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/certs/SOS.info.crt
SSLCertificateKeyFile /etc/ssl/private/SOS.info.key
SSLCertificateChainFile /etc/ssl/certs/SOS.info.root-bundle.crt
#etc..
</VirtualHost>
</IfModule>
Questo è HTTPS VH.
Il contenuto di questi due file può essere pubblicato in un unico file, ma in questo caso la loro gestione ( a2ensite/ a2dissite) sarà più difficile.
Il terzo host virtuale è quello creato per i nostri scopi :
$ cat /etc/apache2/sites-available/http.test-site.conf
<VirtualHost *:80>
ServerName test-site
ServerAlias test-site.SOS.info
DocumentRoot /var/www/test-site
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/test-site.error.log
CustomLog ${APACHE_LOG_DIR}/test-site.access.log combined
<Directory /var/www/test-site>
# Allow .htaccess
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
3. Con questa configurazione è necessario accedere a:
http://localhost # pointed to the directory of the mine Domain
https://localhost # iin our case: /var/www/html (SOS.info), but you should get an error, because the SSL certificate
http://SOS.info # which redirects to https://SOS.info
https://SOS.info # you should have valid SSL certificate
http://www.SOS.info # which is allied to http://SOS.info and redirects to https://SOS.info
https://www.SOS.info # which is allied to https://SOS.info
Nell'esempio principale dovresti accedere e :
http://test-site # pointed to the directory /var/www/test-site
http://test-site.SOS.info # which is allied to http://test-site
Prova ad aprire il sito nel browser web o prova (nel terminale) con i seguenti comandi:
$ curl -L http://test-site/index.html
$ curl -L http://test-site.SOS.info/index.html
Ovviamente, devi avere alcune index.htmlpagine in DocumentRoot :)
Lascerò le prossime note a causa della pedanteria :)
4. È necessario configurare correttamente `/ etc / apache2 / apache2.conf`.
È consigliabile passare un po 'di tempo per migliorare la sicurezza del server. Questi manuali riguardano la configurazione della sicurezza: 1 ° e 2 ° . Qui puoi ottenere il certificato SSL gratuito. Questi siti ti aiuteranno a verificare i tuoi progressi: 1 ° e 2 ° .
Secondo i manuali di sicurezza di cui sopra, il /etc/apache2/apache2.conffile deve essere simile a:
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 60
#KeepAlive Off
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options None FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /var/www/>
Options None FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
# Hide Server type in the http error-pages
ServerSignature Off
ServerTokens Prod
# Etag allows remote attackers to obtain sensitive information
FileETag None
# Disable Trace HTTP Request
TraceEnable off
# Set cookie with HttpOnly and Secure flag.
# a2enmod headers
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
# Clickjacking Attack
Header always append X-Frame-Options SAMEORIGIN
# CX-XSS Protection
Header set X-XSS-Protection "1; mode=block"
# Disable HTTP 1.0 Protocol
RewriteEngine On
RewriteCond %{THE_REQUEST} !HTTP/1.1$
RewriteRule .* - [F]
# Change the server banner @ ModSecurity
# Send full server signature so ModSecurity can alter it
ServerTokens Full
# Alter the web server signature sent by Apache
<IfModule security2_module>
SecServerSignature "Apache 1.3.26"
</IfModule>
Header set Server "Apache 1.3.26"
Header unset X-Powered-By
# Hde TCP Timestamp
# gksu gedit /etc/sysctl.conf
# >> net.ipv4.tcp_timestamps = 0
# Test: sudo hping3 SOS.info -p 443 -S --tcp-timestamp -c 1
# Disable -SSLv2 -SSLv3 and weak Ciphers
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4"
5. Configurare il firewall.
Per consentire / negare l'accesso esterno al server Web è possibile utilizzare UFW (Firewall semplice):
sudo ufw allow http
sudo ufw allow https
Per consentire solo l' tcpuso del protocollo:
sudo ufw allow http/tcp
sudo ufw allow https/tcp
È possibile utilizzare e il numero di porta direttamente:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Nel caso in cui sia possibile ricaricare la "tabella delle regole":
sudo ufw reload
Puoi usare l'interfaccia GUI di UFW, chiamata gufw .
sudo apt update
sudo apt install gufw
gufw &
Scegli il Officeprofilo. Sarà set: Status:ON, Incoming:Denye Outgoing:Allowe aggiungi le regole.
6. Se si dispone di un router, non dimenticare di inoltrare alcune porte:
Se si dispone di un router e si desidera che il proprio server Web sia accessibile da Internet , non dimenticare di aggiungere un port forwarding. Qualcosa di simile a questo .
ServerName 192.168.0.2linea poiché la direttiva ServerName dovrebbe avere il nome come www.server.com e non il numero IP. Penso che questo potrebbe risolvere il problema. Per ServerName dovresti inserire il nome del server se ce l'hai. ServerName consente l'hosting virtuale basato sul nome, che consente di avere più siti Web sullo stesso IP.