ブラウザでApache 2.4.7 Webサーバーにアクセスしようとすると禁止された403エラー


9

同じWebサーバーPCからlocalhostを使用してApache Webサーバーにアクセスすると、Apache2 Ubuntuのデフォルトページが表示されます。

しかし、192.168.0.2を使用してApache Webサーバーにアクセスすると、403 Forbiddenエラーが表示されます(このサーバーにアクセスするためのアクセス権がありません)。

Webサーバーの詳細

  • Ubuntu 14.04 LTS
  • Apacheバージョン2.4.7

所有権コマンド

www-data sudo adduser ftpuser www-data
sudo chown -R www-data:ftpuser /var/www
sudo chmod -R g+rwX /var/www

など/ apache2の/ apache2.confファイル

ServerName 192.168.0.2

<Directory/>
    AllowOverride All
    Require all granted
</Directory>

など/ apache2の/ port.confファイル

NameVirtualHost *:80
Listen *:80

1つのWebサイトの仮想ホスト

<VirtualHost *:80>
    ServerName mysite
    DocumentRoot /var/www/mysite
    <Directory /var/www/mysite>
        Options None FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>    
</VirtualHost>

どの場所でどの設定を行う必要がありますか?助けてください...


私は捨ててしまうServerName 192.168.0.2www.server.comのような名前ではなくIP番号を持っている必要がありServerNameディレクティブとしてラインを。これで問題は解決すると思います。ServerNameがある場合は、サーバーの名前を入力する必要があります。ServerNameは名前ベースの仮想ホスティングを許可し、同じIPでより多くのWebサイトを持つことができます。
誰も

@nobody、すでにファイルから削除されていますが、まだ成功していません。
K Ahir

回答:


7

1. / etc / hostsファイルを次のように構成する必要があります

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-site2番目の「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.htmlDocumentRootにいくつかのページが必要です:)



歩数の理由で次のメモを残します:)


4.適切に設定された `/ etc / apache2 / apache2.conf`が必要です。

Iiは、サーバーのセキュリティを向上させるために時間をかけることをお勧めします。これらのマニュアルは、セキュリティ構成に関するものです:1st2ndここで無料の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:ONIncoming:DenyそしてOutgoing:Allowあなたのルールを追加します。


6.ルーターがある場合は、いくつかのポートを転送することを忘れないでください。

ルーターがあり、インターネットからウェブサーバーにアクセスできるようにする場合は、ポート転送を追加することを忘れないでください。このようなもの


000-default.confファイルはすでに/ etc / apache2 / sites-enabled /フォルダーにあります。だから私はまだ上記のコマンドを使用してそれを有効にする必要がありますか?私にお知らせください。
K Ahir

すでに存在する場合は、それらを使用する必要はありません。
pa4080

多分あなたはこのエラーの理由をで見つけるでしょう/var/log/apache2/error.log
pa4080

コメントを更新しました。
pa4080

このエラーメッセージを取得しています... [Fri Aug 12 17:18:37.224182 2016] [mpm_prefork:notice] [pid 4335] AH00169:SIGTERMをキャッチしてシャットダウンしました[Fri Aug 12 17:18:40.679317 2016] [mpm_prefork:notice] [pid 4571] AH00163:Apache / 2.4.7(Ubuntu)PHP / 5.5.9-1ubuntu4.19が設定されています-通常の操作を再開します[Fri Aug 12 17:18:40.679382 2016] [core:notice] [pid 4571] AH00094 :コマンドライン: '/ usr / sbin / apache2'
K Ahir

3

コマンドを使用して、ファイルを提供しているディレクトリの所有権を変更してください:

sudo chown -R www-data:www:data <directory_where_you_serve_files_from>

私の質問には触れませんでしたが、/ var / wwwフォルダーの特定のグループとユーザーに所有権を既に割り当てています。
K Ahir

0

私の問題を解決したこの回答にあなたをリンクすることになっています。

まず、フォルダに権限を追加します。

sudo chmod -R 775 /var/www

次に、このテキストを追加します。

<Directory /var/www/html>
  AllowOverride All
</Directory>

このファイルの最後に:

/etc/apache2/sites-available/000-default.conf
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.