openedx / openedx-wordpress-ecommerce

You can sell your Open edX courses with WooCommerce using this free and open-source WordPress plugin.
https://docs.openedx.org/projects/wordpress-ecommerce-plugin/en/latest/index.html
GNU General Public License v2.0
11 stars 8 forks source link

Question about using with openedx and Wordpress in docker containers #66

Closed johnny77221 closed 8 months ago

johnny77221 commented 10 months ago

I am trying to use this on docker version of Wordpress 6.3.1, following these steps on the repo: https://github.com/mjstealey/wordpress-nginx-docker except I changed to use image: wordpress:6.3.1-php8.1-fpm after starting tutor local launch, the tutor(openedx) and Wordpress runs successfully and both accessible wordpress is on http://localhost:8443, tutor is http://local.edly.io

I also built network between two containers docker network connect --ip 172.20.128.2 multi-host-network c729d4c7074d #tutor_local-caddy-1 docker network connect --ip 172.20.128.3 multi-host-network f456aad7345b #wp-wordpress

I created OAuth application for wordpress, but when I try to set it in wordpress plugin, it shows up an error

Error: cURL error 7: Failed to connect to localhost port 443 after 0 ms: Couldn't connect to server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://localhost/oauth2/access_token

do you have idea about how to correctly set this up in this case?

截圖 2023-12-26 下午6 17 21
feanil commented 10 months ago

@johnny77221 it looks like you're trying to connect to https://localhost/oauth2/access_token I think it should be http://local.edly.io like you have in your screenshot but maybe that config wasn't saved? In anycase, it makes sense that you got an error fetching the https url for localhost since you don't have TLS setup locally.

johnny77221 commented 10 months ago

they are in different docker containers so I have set up the network to have them connected (72.20.128.3 -> 72.20.128.2) I doubt something happened in caddy that only accepts connections in domain name so I also set /etc/hosts in wordpress container to have local.edly.io point to 172.20.128.2 but somehow the http url was redirected to https so the error message above appears I am not familiar with how the caddy works so I have no idea how to move the next step from now

MaferMazu commented 8 months ago

Hello, @johnny77221, thanks for your patience. I could replicate your error. The only thing I didn't do was create a network.

The error occurs because when you click "Generate JWT Token," the request is generated in the docker container you are running your WordPress, and your Open edX platform should be running in your machine and not inside the WordPress container. And for that reason, you couldn't reach out to the local.edly.io inside the docker container.

An easy way to check that you couldn't reach correctly the localhost inside the WordPress container is running something like this: curl -I http://local.edly.io:8000 You should be able to obtain a response from your machine but not from the WordPress docker container. (Because the local.edly.io:8000 points to localhost:8000, and inside your WP docker container, you don't have it running)

This is not a solution, but I found a workaround that can work for you:

That is the super easy one, but I prefer to still use the local.edly.io, and for that, I did the following steps:

There are probably better ways to do this, but that should be enough for now.

Note: I don't have the issue of changing HTTPS from HTTP in my tests.

Please let me know if this helps you.

References

Side note: If I'm using eox-tenant, I need to add something like http://195.123.xx.x:8000/ in my redirect uris in my Application.

johnny77221 commented 8 months ago

Thanks Setting the domain in /etc/hosts do the trick

when I have created docker network: docker network create --subnet 172.20.0.0/16 --ip-range 172.20.128.0/20 wpedx docker network connect --ip 172.20.128.2 wpedx 621a38811bf6 #tutor_local-caddy-1 docker network connect --ip 172.20.128.3 wpedx f456aad7345b #wp-wordpress

I should set record 172.20.128.2 local.edly.io in Wordpress's container so that wordpress can connect to local.edly.io(access caddy) and token can be generated