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...
test-site
2番目の「localhost」はどこにありますか。でmy-hostname
定義されている「システムホスト名」/etc/hostname
です。
2. 仮想ホスト(VH)を定義して有効にする必要があります。
デフォルトのHTTP VHがあります。に配置され/etc/apache2/sites-available/
ます。ファイル名は000-default.conf
です。それを編集し(必要に応じて名前を変更したり、それに基づいて他の.confファイルを作成したり)、その後で有効にする必要があります。
「ソフトシンボリックリンク」を作成して、手動で有効にすることができます。
sudo ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/
または、同じようにするa2ensiteと呼ばれるApache2ツールを使用できます。
sudo a2ensite 000-default.conf
3つの仮想ホストがあり、SSLが有効で、プライベートドメインが登録されていると仮定します(例としてSOS.info)。
/etc/apache2/sites-available/http.SOS.info.conf
/etc/apache2/sites-available/https.SOS.info.conf
そして、このトピックの目的のために作成されたもの:
/etc/apache2/sites-available/http.test-site.conf
最初の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>
これはすべてのHTTPリクエストを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>
これはHTTPS VHです。
これら2つのファイルのコンテンツは1つのファイルに投稿できますが、この場合、それらの管理(a2ensite
/ a2dissite
)はより困難になります。
3番目の仮想ホストは、目的のために作成された仮想ホストです。
$ 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.この構成では、以下にアクセスする必要があります。
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
主な例では、アクセスして:
http://test-site # pointed to the directory /var/www/test-site
http://test-site.SOS.info # which is allied to http://test-site
Webブラウザーでサイトを開くか、次のコマンドを(ターミナルで)試してください。
$ curl -L http://test-site/index.html
$ curl -L http://test-site.SOS.info/index.html
もちろん、index.html
DocumentRootにいくつかのページが必要です:)
歩数の理由で次のメモを残します:)
4.適切に設定された `/ etc / apache2 / apache2.conf`が必要です。
Iiは、サーバーのセキュリティを向上させるために時間をかけることをお勧めします。これらのマニュアルは、セキュリティ構成に関するものです:1stと2nd。ここで無料のSSL証明書を取得できます。これらのサイトは、進捗状況を確認するのに役立ちます:1番目と2番目。
上記のセキュリティマニュアルによると、/etc/apache2/apache2.conf
ファイルは次のようになります。
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.ファイアウォールを設定します。
できるようにするには/あなたが使用できるWebサーバーへの外部アクセス拒否UFW(合併症のないファイアウォールを):
sudo ufw allow http
sudo ufw allow https
tcp
プロトコルのみの使用を許可するには:
sudo ufw allow http/tcp
sudo ufw allow https/tcp
とポート番号を直接使用できます。
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
「ルールテーブル」をリロードできるように:
sudo ufw reload
gufwと呼ばれるUFWのGUIインターフェイスを使用できます。
sudo apt update
sudo apt install gufw
gufw &
Office
プロファイルを選択します。それは設定します:Status:ON
、Incoming:Deny
そしてOutgoing:Allow
あなたのルールを追加します。
6.ルーターがある場合は、いくつかのポートを転送することを忘れないでください。
ルーターがあり、インターネットからウェブサーバーにアクセスできるようにする場合は、ポート転送を追加することを忘れないでください。このようなもの。
ServerName 192.168.0.2
www.server.comのような名前ではなくIP番号を持っている必要がありServerNameディレクティブとしてラインを。これで問題は解決すると思います。ServerNameがある場合は、サーバーの名前を入力する必要があります。ServerNameは名前ベースの仮想ホスティングを許可し、同じIPでより多くのWebサイトを持つことができます。