大网数据广告活动
服务器运维问答

Wordpress on DigitalOcean http://example.com not working, but all other combinations of https://example.com and http://www.example.com are

· 52CE 我爱测

This is a hard question to google, or even title. I can hit my Wordpress site successfully using this: http://www.example.com/ https://www.example.com/ https://example.com/ But this fails: http://example.com/ If you try to hit th…

问题原文

原帖链接 · Tim · CC BY-SA 3.0

This is a hard question to google, or even title.

I can hit my Wordpress site successfully using this:

http://www.example.com/

https://www.example.com/

https://example.com/

But this fails:

http://example.com/

If you try to hit the domain from this address, you see a blue DigitalOcean-branded web page, with a picture of a shark and the following error: "Please log into your droplet via SSH to configure your LAMP installation."

I have a DigitalOcean droplet running Ubuntu 16.04 with Apache 2 and several domains. One of the domains has a Wordpress site that was migrated over from another host. The domain is configured the same as all my other domains, including a certificate installed via letsencrypt.

I do not believe my problem is with the certificate. I believe the problem has to do with Wordpress, because the other sites on my server are working just fine in all 4 conditions (http:// and https:// and www and non-www)

Here is my (anonymized) .conf file:

    <VirtualHost *:80>
    ServerAdmin [email omitted]
    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]

and here is my .htaccess folder inside of /var/www/example

        # 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

and here are my DNS settings, pasted and anonymized:

        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.    

and here is my output of 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

已采纳解答

原帖链接 · Tom · CC BY-SA 3.0

Possibility #1

It looks like your default VirtualHost for *:80, using the config file 000-default.conf is matching namevhost example.com at the top of the output... ;

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)

whereas, you want it to match here;

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

What's probably happening is that the page with the text "Please log into your droplet via SSH to configure your LAMP installation." is the default content from /var/www/html.

So I would try removing the /etc/apache2/sites-enabled/000-default.conf and ensuring that the example.com is matching the correct VHost.

Possibility #2

Check your settings in wp-config.php, it should match what your redirects are ultimately pointing to;

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

This sometimes causes problems with wordpress, when it doesn't match what apache wants.

Further troubleshooting

The other thing is that you have pasted config for a http://example.com:80/ site;

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

However the rewrite rule looks like it would bounce every request to https://

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

So we'd probably need to see the https config as well.

Also, you should probably paste the output of access.log and error.log pertaining to one specific request, to see what redirects actually happened.

Also, if you still can't see the problem, you can turn on rewrite logging;

 LogLevel alert rewrite:trace3

and then trace the log for requests;

tail -f error_log|fgrep '[rewrite:' 

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。