DigitalOceanのWordpress http://example.comは機能しないが、https://example.comとhttp://www.example.comの他のすべての組み合わせは機能する

DigitalOceanのWordpress http://example.comは機能しないが、https://example.comとhttp://www.example.comの他のすべての組み合わせは機能する

これはグーグルで検索したり、タイトルを付けたりするのも難しい質問です。

これを使用すると、Wordpress サイトに正常にアクセスできます。

http://www.example.com/

https://www.example.com/

https://example.com/

しかし、これは失敗します:

http://example.com/

このアドレスからドメインにアクセスしようとすると、サメ​​の写真と次のエラーを含む青い DigitalOcean ブランドの Web ページが表示されます: 「LAMP インストールを構成するには、SSH 経由でドロップレットにログインしてください。」

私は、Apache 2 と複数のドメインを備えた Ubuntu 16.04 を実行する DigitalOcean ドロップレットを持っています。ドメインの 1 つには、別のホストから移行された Wordpress サイトがあります。このドメインは、letsencrypt 経由でインストールされた証明書を含め、他のすべてのドメインと同じように構成されています。

私の問題は証明書に関係しているとは思いません。私のサーバー上の他のサイトは 4 つの条件 (http:// と https://、www と non-www) すべてで正常に動作しているので、問題は Wordpress に関係していると思います。

これが私の(匿名化された).conf ファイルです:

    <VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com

    DocumentRoot /var/www/example
    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>
    <Directory /var/www/example>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xh$
    </IfModule>

RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

そして、ここに /var/www/example 内の .htaccess フォルダがあります。

        # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#test
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# END WordPress

以下は私の DNS 設定を貼り付けて匿名化したものです。

        CNAME   
ftp.example.com is an alias of example.com. 

A   
example.com directs to 159.65.36.136

CNAME
www.example.com is an alias of example.com. 

NS  
example.com directs to ns1.digitalocean.com.    

NS  
example.com directs to ns2.digitalocean.com.    

NS  
example.com directs to ns3.digitalocean.com.    

そしてこれがapache2ctl -Sの出力です

            VirtualHost configuration:
*:443                  is a NameVirtualHost
        default server othersite1.com (/etc/apache2/sites-enabled/othersite1.com-le-ssl.conf:2)
        port 443 namevhost othersite1.com (/etc/apache2/sites-enabled/othersite1.com-le-ssl.conf:2)
                alias www.othersite1.com
        port 443 namevhost othersite2.co (/etc/apache2/sites-enabled/othersite2.co-le-ssl.conf:2)
                alias www.othersite2.co
        port 443 namevhost example.com (/etc/apache2/sites-enabled/example.com-le-ssl.conf:2)
                alias www.example.com
        port 443 namevhost othersite3.com (/etc/apache2/sites-enabled/othersite3.com-le-ssl.conf:2)
                alias www.othersite3.com
        port 443 namevhost othersite4.com (/etc/apache2/sites-enabled/othersite4.com-le-ssl.conf:2)
                alias www.othersite4.com
        port 443 namevhost othersite5.net (/etc/apache2/sites-enabled/othersite5.net-le-ssl.conf:2)
                alias www.othersite5.net
        port 443 namevhost othersite6.com (/etc/apache2/sites-enabled/othersite6.com-le-ssl.conf:2)
                alias www.othersite6.com
*:80                   is a NameVirtualHost
        default server example.com (/etc/apache2/sites-enabled/000-default.conf:1)
        port 80 namevhost example.com (/etc/apache2/sites-enabled/000-default.conf:1)
        port 80 namevhost othersite1.com (/etc/apache2/sites-enabled/othersite1.com.conf:1)
                alias www.othersite1.com
        port 80 namevhost othersite2.co (/etc/apache2/sites-enabled/othersite2.co.conf:1)
                alias www.othersite2.co
        port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com.conf:1)
                alias www.example.com
        port 80 namevhost othersite3.com (/etc/apache2/sites-enabled/othersite3.com.conf:1)
                alias www.othersite3.com
        port 80 namevhost othersite4.com (/etc/apache2/sites-enabled/othersite4.com.conf:1)
                alias www.othersite4.com
        port 80 namevhost othersite5.net (/etc/apache2/sites-enabled/othersite5.net.conf:1)
                alias www.othersite5.net
        port 80 namevhost othersite6.com (/etc/apache2/sites-enabled/othersite6.com.conf:1)
                alias www.othersite6.com
    ServerRoot: "/etc/apache2"
    Main DocumentRoot: "/var/www/html"
    Main ErrorLog: "/var/log/apache2/error.log"
    Mutex rewrite-map: using_defaults
    Mutex ssl-stapling-refresh: using_defaults
    Mutex ssl-stapling: using_defaults
    Mutex ssl-cache: using_defaults
    Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
    Mutex mpm-accept: using_defaults
    Mutex watchdog-callback: using_defaults
    PidFile: "/var/run/apache2/apache2.pid"
    Define: DUMP_VHOSTS
    Define: DUMP_RUN_CFG
    User: name="www-data" id=33
    Group: name="www-data" id=33

答え1

可能性#1

のデフォルトの VirtualHost のように見えますが*:80、構成ファイルを使用すると、出力の先頭の000-default.confnamevhost と一致します... ;example.com

VirtualHost configuration:
    default server example.com (/etc/apache2/sites-enabled/000-default.conf:1)
    port 80 namevhost example.com (/etc/apache2/sites-enabled/000-default.conf:1)

一方、ここでは一致させたいのです。

    port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com.conf:1)
    alias www.example.com

おそらく、「LAMP インストールを構成するには、SSH 経由でドロップレットにログインしてください。」というテキストを含むページが、 のデフォルト コンテンツであると考えられます/var/www/html

したがって、 を削除して/etc/apache2/sites-enabled/000-default.conf、 がexample.com正しい VHost と一致していることを確認します。

可能性その2

の設定を確認してくださいwp-config.php。リダイレクトが最終的に指しているものと一致する必要があります。

define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');

これが Apache の要件と一致しない場合、WordPress で問題が発生することがあります。

さらなるトラブルシューティング

もう一つは、http://example.com:80/サイト;

 <VirtualHost *:80>
ServerName example.com 
...
</VirtualHost>

しかし、書き換えルールは、すべてのリクエストをhttps://にバウンスするように見えます。

RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

したがって、おそらく https 構成も確認する必要があります。

また、実際にどのようなリダイレクトが発生したかを確認するには、特定のリクエストに関連する access.log と error.log の出力を貼り付ける必要があります。

また、それでも問題が見つからない場合は、書き換えログをオンにすることができます。

 LogLevel alert rewrite:trace3

次に、リクエストのログをトレースします。

tail -f error_log|fgrep '[rewrite:' 

関連情報