evertramos / docker-wordpress

Wordpress Docker container using SSL Certificates with LetsEncrypt
https://evertramos.github.io/docker-wordpress/
MIT License
484 stars 156 forks source link

nginx error importing old blog (502 Bad Gateway) #20

Closed casaucao closed 6 years ago

casaucao commented 6 years ago

With a fresh install I have imported a wordpress.com blog through Wordpress importer and the generated xml file.

After few seconds (maybe few minutes) I got an error:

502 Bad Gateway

Looking in nginx logs files I can see:

 2018/07/06 16:56:37 [error] 18#18: *29 upstream prematurely closed connection while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: xxx, request: "POST /wp-admin/admin.php?import=wordpress&step=2 HTTP/2.0", upstream: "http://172.18.0.6:80/wp-admin/admin.php?import=wordpress&step=2", host: "xxx", referrer: "https://xxx.xx/wp-admin/admin.php?import=wordpress&step=1&_wpnonce=c9e9bc6704"

Could anybody help me?

evertramos commented 6 years ago

What is the size of the file?

casaucao commented 6 years ago

Exported xml file size is 280kb.

Once exported, I choose Wordpress importer, and I select "download and import file attachments", then I got the 502 error (upstream prematurely closed connection while reading response header from upstream)

evertramos commented 6 years ago

That's weird... this is the log of the proxy? of the wordpress container? I thing this probably not related with the repo itself.. but the wordpress data...

Do you have the same url name for the domain you are having?

casaucao commented 6 years ago

Actually weird. The log is from nginx container, not from wordpress container. I don't really know how to see error logs from wordpress container. This is what I do:

docker logs --details -f [wordpress_container]

and I get the following info while I'm trying to import the xml file:

 172.18.0.4 - - [07/Jul/2018:11:33:20 +0000] "GET /wp-admin/import.php?import=wordpress HTTP/1.1" 200 6617 "https://example.com/wp-admin/import.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
 172.18.0.4 - - [07/Jul/2018:11:33:31 +0000] "POST /wp-admin/admin.php?import=wordpress&step=1&_wpnonce=7dad11711c HTTP/1.1" 200 6904 "https://example.com/wp-admin/import.php?import=wordpress" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
 172.18.0.4 - - [07/Jul/2018:11:34:00 +0000] "GET /wp-admin/load-styles.php?c=0&dir=ltr&load%5B%5D=dashicons,buttons,forms,l10n,login&ver=4.9.7 HTTP/1.1" 200 37059 "https://example.com/wp-login.php" "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36"
 172.18.0.4 - - [07/Jul/2018:11:34:01 +0000] "GET /favicon.ico HTTP/1.1" 404 465 "-" "Googlebot-Image/1.0"

Apparently there are no errors but I think this is the access log instead error log.


Domains are differents. Old is example.wordpress.com and new is example.com.


AFAIK wordpress+apache container is going to retreive data (posts, comments, images,... ) from example.wordpress.com through the nginx proxy container. At some stage, wordpress or apache container fails and nginx proxy shows a 502 error message logging "upstream prematurely closed connection while reading response header from upstream" in the nginx container. At least this is what I think, but I don't know how to identify the issue in order to solve it.

evertramos commented 6 years ago

After the import the container remains up?

Try to add the wp-cli to your composer and update the url in database or pull up a phpmyadmin in your docker and check the database what might be wrong... I don´t think there is something in container itself... might be wordpress settings... not sure at all

casaucao commented 6 years ago

Yes, after the import the container remains up!


Database is ok. No issues.


I'm added wp-cli as follow:

sudo docker run -it --user root --rm --volumes-from wordpress --network container:[container_id] wordpress:cli /bin/sh

Once I got a shell, I type:

wp import exported_file.xml --authors=create --debug

And the importer script FAILS:

Processing post #145 ("IMG_8180-1") (post_type: attachment)
-- 57 of 133 (in file example.wordpress.2018-07-05.xml)
-- Sun, 08 Jul 2018 08:19:59 +0000
Killed

If I remove that media entry from the exported file all works fine. I open that image in a browser and that image is 5184x3456px. Maybe an OOM error?

casaucao commented 6 years ago

I fear this is not an OOM error.

I have deleted all database and wordpress files and containers, then I reinstalled wordpress from scratch. When I have launched wp import I have discovered that there are multiples media entries that "kill" the process.

All images are about 4000x2000 5000x3000px ~~.

If I launch again the wp-cli import command, all works fine (the new process imports the failing image and continue importing the rest of the images until the next "killed")

I have to repeat

wp import exported_file.xml --authors=create --debug

at least 15 times in order to get all the images.

casaucao commented 6 years ago

SOLVED!

It's was a memory issue. The containers were running on a 512MB RAM instance (too few mem) Adding a Swap page solved the problem for me.

This link just made my day: https://stackoverflow.com/a/13999800

Thank you very much for your support. You did a very great job!

evertramos commented 6 years ago

Thanks @casaucao!!

It seems it did a better job! by solving the issue. Thanks for sharing and we will keep that tip for the future.

Cheers!