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...
Gdzie test-sitejest drugi „localhost”. I my-hostnamejest to „Systemowa nazwa hosta” zdefiniowana w /etc/hostname.
2. Powinieneś zdefiniować i włączyć Virtual Host (VH):
Istnieje domyślny VH HTTP. Jest umieszczony w /etc/apache2/sites-available/. Nazwa pliku to 000-default.conf. Musisz go edytować (możesz go zmienić, jeśli chcesz lub utworzyć inne pliki .conf, na jego podstawie), a następnie musisz go włączyć.
Możesz włączyć go ręcznie, tworząc „miękki, symboliczny link”:
sudo ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/
Lub możesz użyć narzędzia Apache2 o nazwie a2ensite , które tworzą to samo:
sudo a2ensite 000-default.conf
Załóżmy, że istnieją 3 wirtualne hosty , włączony protokół SSL i zarejestrowana domena prywatna (na przykład SOS.info):
/etc/apache2/sites-available/http.SOS.info.conf
/etc/apache2/sites-available/https.SOS.info.conf
I taki, który został stworzony na potrzeby tego tematu:
/etc/apache2/sites-available/http.test-site.conf
Zawartość pierwszych 2 VH to:
$ 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>
Ten przekierowuje wszystkie żądania HTTP do 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>
To jest HTTPS VH.
Zawartość tych dwóch plików można opublikować w jednym pliku, ale w tym przypadku ich zarządzanie ( a2ensite/ a2dissite) będzie trudniejsze.
Trzeci wirtualny host to taki, który został stworzony do naszych celów :
$ 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. W tej konfiguracji należy uzyskać dostęp:
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
Na głównym przykładzie powinieneś uzyskać dostęp i :
http://test-site # pointed to the directory /var/www/test-site
http://test-site.SOS.info # which is allied to http://test-site
Spróbuj otworzyć stronę w przeglądarce internetowej lub po prostu spróbuj (w terminalu) z następnymi poleceniami:
$ curl -L http://test-site/index.html
$ curl -L http://test-site.SOS.info/index.html
Oczywiście musisz mieć kilka index.htmlstron w ich DocumentRoot :)
Zostawię kolejne notatki ze względu na pedanterię :)
4. Potrzebujesz poprawnie skonfigurowanego `/ etc / apache2 / apache2.conf`.
Ii to dobry pomysł, aby poświęcić trochę czasu na poprawę bezpieczeństwa serwera. Te instrukcje dotyczą konfiguracji zabezpieczeń: 1. i 2 .. Tutaj możesz uzyskać bezpłatny certyfikat SSL. Strony te pomogą ci sprawdzić swoje postępy: 1. i 2. miejsce .
Zgodnie z powyższymi instrukcjami bezpieczeństwa /etc/apache2/apache2.confplik musi wyglądać następująco:
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. Skonfiguruj zaporę ogniową.
Aby zezwolić / zabronić zewnętrznego dostępu do twojego serwera WWW, możesz użyć UFW (nieskomplikowana zapora ogniowa):
sudo ufw allow http
sudo ufw allow https
Aby zezwolić tylko na tcpużycie protokołu:
sudo ufw allow http/tcp
sudo ufw allow https/tcp
Możesz użyć bezpośrednio numeru portu:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Na wypadek, gdybyś mógł przeładować „tabelę reguł”:
sudo ufw reload
Możesz użyć interfejsu GUI UFW, zwanego gufw .
sudo apt update
sudo apt install gufw
gufw &
Wybierz Officeprofil. Będzie to zestaw: Status:ON, Incoming:Denya Outgoing:Allowi dodać swoje zasady.
6. Jeśli masz router, nie zapomnij przekierować niektórych portów:
Jeśli masz router i chcesz, aby twój serwer WWW był dostępny przez Internet , nie zapomnij dodać przekierowania portów. Coś w tym stylu .
ServerName 192.168.0.2linię, ponieważ dyrektywa ServerName powinna mieć nazwę taką jak www.server.com, a nie numer IP. Myślę, że to może rozwiązać problem. W polu NazwaSerwera należy podać nazwę serwera, jeśli go masz. ServerName pozwala na wirtualny hosting oparty na nazwie, który pozwala mieć więcej stron internetowych pod tym samym adresem IP.