我使用自定义 Docker 容器在 Linux 上的 Azure App Service 上安装的 Wordpress 响应时间非常慢。页面加载大约需要 20-40 秒。
我安装了故障排除插件,在向以下 URL 发出请求时指示问题是“cURL 错误 28:在 N 毫秒后解析超时”
- https://api.wordpress.org/core/version-check/1.7/
- http://api.wordpress.org/core/version-check/1.7/
- https://api.wordpress.org/plugins/update-check/1.1/
- http://api.wordpress.org/plugins/update-check/1.1/
- https://api.wordpress.org/themes/update-check/1.1/
- http://api.wordpress.org/themes/update-check/1.1/
cURL 在 scm-site 命令行上运行良好。例如,这可以正常工作。
curl -X POST http://api.wordpress.org/core/version-check/1.7/
编辑 如果我通过 ssh 进入容器并运行此 php 代码,它可以正常工作。
<?php
$url = 'http://api.wordpress.org/core/version-check/1.7/';
$fields = array(
'version' => urlencode('4.8.1'),
'php' => urlencode('7.1.8'),
'locale' => urlencode('fi'),
'mysql' => urlencode('5.6.26.0'),
'local_package' => urlencode('fi'),
'blogs' => urlencode('1'),
'users' => urlencode('4'),
'multisite_enabled' => urlencode('0'),
'initial_db_version' => urlencode('26691')
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_exec($ch);
curl_close($ch);
它返回以下内容。
root@71c3bba3a35e:/home/site/wwwroot# php curl.php
{"offers":[{"response":"upgrade","download":"http:\/\/downloads.wordpress.org\/release\/wordpress-4.8.1.zip","locale":"en_US","packages":{"full":"http:\/\/downloads.wordpress.org\/release\/wordpres
s-4.8.1.zip","no_content":"http:\/\/downloads.wordpress.org\/release\/wordpress-4.8.1-no-content.zip","new_bundled":"http:\/\/downloads.wordpress.org\/release\/wordpress-4.8.1-new-bundled.zip","par
tial":false,"rollback":false},"current":"4.8.1","version":"4.8.1","php_version":"5.2.4","mysql_version":"5.0","new_bundled":"4.7","partial_version":false}],"translations":[]}
我的 Docker 镜像使用 php:7.1.8-apache。
这是我的 Dockerfile。
FROM php:7.1.8-apache
EXPOSE 80 443 2222
RUN apt-get update -y && apt-get install -y --no-install-recommends \
ssl-cert \
ca-certificates \
apt-utils \
vim \
curl \
mysql-client \
openssh-server \
libmcrypt-dev \
libcurl4-gnutls-dev \
libicu-dev \
&& docker-php-ext-install -j$(nproc) iconv \
mcrypt \
mysqli \
json \
mbstring \
curl \
intl \
&& echo "root:Docker!" | chpasswd \
&& ln -s /home/LogFiles /var/log/apache2
ENV APACHE_CONFDIR=/etc/apache2 \
APACHE_ENVVARS=/etc/apache2/envvars \
APACHE_LOCK_DIR=/var/lock/apache2 \
APACHE_LOG_DIR=/var/log/apache2 \
APACHE_RUN_DIR=/var/run/apache2 \
APACHE_PID_FILE=/var/run/apache2/apache2.pid \
APACHE_RUN_USER=www-data \
APACHE_RUN_GROUP=www-data
WORKDIR /usr/local
COPY config/wprun.sh config/wp-config.php /usr/local/
COPY config/sshd_config /etc/ssh/
COPY config/php.ini /usr/local/etc/php/
RUN chmod 755 wprun.sh && \
rm -R /var/www/html && \
a2enmod rewrite && \
a2enmod expires && \
a2enmod include && \
sed -i "s@/var/www@/home/site/wwwroot@" /etc/apache2/sites-enabled/000-default.conf && \
sed -i "s@/var/www@/home/site/wwwroot@" /etc/apache2/apache2.conf
CMD ["/bin/bash","wprun.sh"]
编辑 2 这GitHub issue似乎相似。建议使用OpenDNS resolvers .这可能是 DNS 问题吗?如果是这样,那么它如何与 Docker 和 Azure 一起工作?
编辑 3 这似乎是一个 DNS 问题。这是 Azure 中的 resolv.conf 文件。
search reddog.microsoft.com
nameserver 127.0.0.11
options timeout:1 attempts:5 ndots:0
当我将名称服务器更改为 8.8.8.8 时,页面会在一到两秒内加载。所有 cURL 错误也会消失。
如果我没理解错的话,Docker mounts the host machine's resolv.conf file和 DNS 设置应使用 Docker 运行命令选项进行设置。不建议直接更改这些文件。
The exact details of how Docker manages the DNS configurations inside the container can change from one Docker version to the next. So you should not assume the way the files such as /etc/hosts, /etc/resolv.conf are managed inside the containers and leave the files alone and use the following Docker options instead.
但是,似乎无法在 Azure 中设置 docker run 参数。
最佳答案
curl 的 scm-site 命令行在适用于 Linux 的 Azure WebApps 的主机上运行,而不是在 docker 容器内运行。
有一个问题 curl fails inside container on https connection在 GitHub moby/moby
上,和你的很相似。据此,我认为您需要通过 PHP 方法 curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
为您的 curl 调用设置 --tlsv1
选项适用于 Linux 的 Azure WebApp 的 docker 容器。
希望对您有所帮助。
关于php - Linux 上 Azure 应用服务上的 Wordpress 上的 "cURL error 28: Resolving timed out",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46155659/