简体   繁体   English

AWS 上的 WordPress,带有 ECS、EFS 和 ELB 返回 502

[英]WordPress on AWS with ECS, EFS and ELB returning 502

I have a site based on WordPress 4.9.6 that is deployed using AWS ECS, with EFS used to store WordPress' files.我有一个基于 WordPress 4.9.6 的站点,该站点使用 AWS ECS 进行部署,EFS 用于存储 WordPress 的文件。 As database I use an AWS Aurora MySQL 5.7 compatible instance.作为数据库,我使用 AWS Aurora MySQL 5.7 兼容实例。 I have also set up an application load balancer to access the containerized WordPress instances.我还设置了一个应用程序负载均衡器来访问容器化的 WordPress 实例。 (More specifics on the setup below.) (下面设置的更多细节。)

Problem overview问题概述

This setup does seem to work in most cases.这种设置似乎在大多数情况下都有效。 Ie I am able to do GET requests on the site.即我能够在网站上执行GET请求。 I can login in, see the dashboard and often times do updates successfully.我可以登录,查看仪表板,并且经常可以成功更新。 The problem I face is that also often times my update attempts result in 502 Bad Gateway response when I commit my update, ie doing POST /wp-admin/post.php .我面临的问题是,当我提交更新时,我的更新尝试也经常导致502 Bad Gateway响应,即执行POST /wp-admin/post.php

Specifics规格

Setup设置

First my DB instance writer is populated with a dump of my local dev database.首先,我的数据库实例编写器填充了本地开发数据库的转储。 The database URL entries pointing back to the site itself, eg siteurl and home in the options table, have values with https .指向站点本身的数据库 URL 条目,例如选项表中的siteurlhome ,具有带有https值。

The EFS was created with performance mode General Purpose . EFS 是使用性能模式通用创建的。 I originally tried with mode Max I/O , but resources suggesting to rather use the former mode.我最初尝试使用模式Max I/O ,但资源建议宁愿使用前一种模式。 However, toggling performance mode has not change the frequency of 502 errors.但是,切换性能模式并没有改变 502 错误的频率。

My Amazon Linux ECS cluster instances are provisioned to mount an EFS volume using NFSv4.1 as suggested by AWS ( mount options nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 ).我的 Amazon Linux ECS 集群实例被配置为使用 AWS 建议的 NFSv4.1 挂载 EFS 卷( mount选项nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 )。

I have a Docker image derived from the official WordPress image in which I update the original image /usr/src/wordpress with my custom content.我有一个源自官方 WordPress 映像的 Docker 映像,我在其中使用自定义内容更新了原始映像/usr/src/wordpress The custom content includes ao an updated wp_config.php in which I set $_SERVER['HTTPS']='on';自定义内容包括更新的wp_config.php ,我在其中设置了$_SERVER['HTTPS']='on';

Putting pieces together my ECS task definition uses my custom Docker image and mounts a directory on my EFS drive as Docker volume in the Docker container.将我的 ECS 任务定义组合在一起,使用我的自定义 Docker 映像并在我的 EFS 驱动器上挂载一个目录作为 Docker 容器中的 Docker 卷。 Bottom line here is that when I create an ECS service with the task definition the container spins up and writes to /var/www/html which I subsequently can see in my EFS drive.这里的底线是,当我使用任务定义创建 ECS 服务时,容器会旋转并写入/var/www/html ,我随后可以在我的 EFS 驱动器中看到它。 This all seems fine and dandy.这一切看起来都很好。

My containerized WordPress instances are then successfully registered in a target group I've previously set up for an application load balancer.然后,我的容器化 WordPress 实例成功注册到我之前为应用程序负载均衡器设置的目标组中。

I can then access my site over https protocol.然后我可以通过 https 协议访问我的网站。 If I try to use http I am redirected to https as planned.如果我尝试使用 http,我会按计划重定向到 https。 I can open the landing page.我可以打开登陆页面。 When I log in I try to edit the landing page.当我登录时,我尝试编辑登录页面。

Problem问题

This is where I face the real problem.这是我面临真正问题的地方。 Often times, but not always, when I do an update on the landing page and click the Update button I get a 502 Bad Gateway response to the POST /wp-admin/post.php request.通常,但并非总是如此,当我在登录页面上进行更新并单击“更新”按钮时,我会收到对POST /wp-admin/post.php请求的 502 Bad Gateway 响应。 Also often when I start to edit and GET /wp-admin/post.php?post=2&action=edit is requested I get the same 502.也经常当我开始编辑并请求GET /wp-admin/post.php?post=2&action=edit ,我得到相同的 502。

I don't see much pattern in when I do and do not get the 502. I have tried to update both textual contents as well as adding images to the landing page.当我这样做并且没有得到 502 时,我没有看到太多模式。我尝试更新文本内容以及将图像添加到登录页面。 The 502 happens sometimes but not always in either case. 502 有时会发生,但并非总是如此。

Also I tried to remedy the problem as I suspected it had to do with the use of EFS and subsequent synchronization problems between the two ECS instances I have set up for the test.我还试图解决这个问题,因为我怀疑它与 EFS 的使用以及我为测试设置的两个 ECS 实例之间的后续同步问题有关。 The following attempts were made, without seeing significant improvement.进行了以下尝试,但没有看到显着的改进。

Finally I reduced the number of ECS service tasks from 2 to 1 but the problem still persists.最后我将 ECS 服务任务的数量从 2 个减少到 1 个,但问题仍然存在。

As an error message in the browser console when meeting the 502 I often, possibly always, see the following: The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.作为遇到 502 时浏览器控制台中的错误消息,我经常(可能总是)看到以下内容: The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.

So, does anyone have clue about what to try next and where to look for indications to the reason for the problem?那么,有没有人知道下一步要尝试什么以及在哪里寻找问题原因的迹象?

It looks like following this看起来像这样

https://wordpress.org/support/article/editing-wp-config-php/#increasing-memory-allocated-to-php https://wordpress.org/support/article/editing-wp-config-php/#increasing-memory-allocated-to-php

Helped resolve my issue, the usual time period where it would time out it has stopped.帮助解决了我的问题,它会超时的通常时间段已经停止。 TLDR; TLDR; During the Dockerfile build process, I added the following lines在 Dockerfile 构建过程中,我添加了以下几行

# Copy php.ini Over to Container
COPY php.ini /usr/local/etc/php/
COPY phpinfo.php /var/www/html/wp-admin/
COPY .htaccess /var/www/html

Php.ini配置文件

upload_max_filesize = 500M
post_max_size = 256M
memory_limit = 256M
max_execution_time = 1800
max_input_time = 180
max_input_vars = 5000

.htaccess .htaccess

php_value upload_max_file 500M
php_value post_max_size 256M
php_value memory_limit 256M
    

phpinfo.php This is accessible by navigating to /wp-admin/phpinfo.php It will give you a summary of the current WP Configuration to see if the changes have been implemented or not, also great for troubleshooting phpinfo.php 这可以通过导航到 /wp-admin/phpinfo.php 访问它会给你当前 WP 配置的摘要,看看是否已经实施了更改,也非常适合故障排除

<?php
phpinfo();
?>

You could either update your task definitions with the new Container built into the ECR, (Not sure if you've automated this ? )您可以使用 ECR 中内置的新容器更新您的任务定义,(不确定您是否已将其自动化?)

Or just access the EC2's via Bastion host and then docker exec -it and edit the files manually, Seeming that you have an EFS it'll be static.或者只是通过堡垒主机访问 EC2,然后 docker exec -it 并手动编辑文件,看起来你有一个 EFS 它会是静态的。

This helped my time out issue.这有助于我的超时问题。 Let me know how you go!让我知道你怎样去!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM