vfarcic / docker-flow-proxy

Docker Flow Proxy
http://proxy.dockerflow.com/
600 stars 17 forks source link

Unable to get the response From apache server when using vfarcic.docker-flow-proxy #67

Closed shibli786 closed 7 years ago

shibli786 commented 7 years ago

hi ,

I am trying to deploy dockerized laravel 5+ app on swarm cluster having 7 nodes (3 manager +4 workers) in google compute engine by using vfacic /docker-flow-proxy but after setting it up as described in documentation demo i am unable to access the page. Error page shows that

503 Service Unavailable

No server is available to handle this request.

what i have done is i have created two overlay network proxy and go-demo

then i run on swarm master

sudo docker service create --name mysql_db \ --network go-demo \ shibli786/mysql

sudo docker service create --name laravel_app \ -e DB=mysql_db \ --network go-demo \ --network proxy \ shibli786/laravelapp

sudo docker service create --name proxy \ -p 80:80 \ -p 443:443 \ -p 8080:8080 \ --network proxy \ -e MODE=swarm \ vfarcic/docker-flow-proxy

curl "http://127.0.0.1:8080/v1/docker-flow-proxy/reconfigure?serviceName=laravel_app&servicePath=/&port=80"

i get success message as "Status":"OK","Message":"","ServiceName":"laravel_app","AclName":"","ServiceColor":"","ServicePath":[" /a"],"ServiceDomain":"","ConsulTemplateFePath":"","ConsulTemplateBePath":"","PathType":"","SkipCheck":f alse,"Mode":"swarm","Port":"80","Distribute":false}

After This set up

Issue 1 When i curl localhost/ on any node it goes into infinite loop Issue 2 when i curl 127.0.0.1/ i get an error saying server unavailable

I don't know that is issue is with my configuration or vfarcic/docker-flow-proxy.

Any way thanks for your precious time..

vfarcic commented 7 years ago

Hi,

Seems that you application (shibli786/laravelapp) is not listening port 80. From what I could see, it does not respond to it port 80 (with or without the proxy).

Here are the commands I run.

git clone https://github.com/vfarcic/docker-flow-proxy.git

cd docker-flow-proxy

chmod +x scripts/swarm-cluster.sh

scripts/swarm-cluster.sh

eval $(docker-machine env node-1)

docker node ls

docker network create --driver overlay proxy

docker network create --driver overlay go-demo

docker service create --name mysql_db \
    --network go-demo \
    shibli786/mysql

docker service create --name laravel_app \
    -e DB=mysql_db \
    --network go-demo \
    --network proxy \
    shibli786/laravelapp

docker service create --name proxy \
    -p 80:80 \
    -p 443:443 \
    -p 8080:8080 \
    --network proxy \
    -e MODE=swarm \
    vfarcic/docker-flow-proxy

docker service ls # Wait until all replicas are running

curl "http://$(docker-machine ip node-1):8080/v1/docker-flow-proxy/reconfigure?serviceName=laravel_app&servicePath=/&port=80"

curl "http://$(docker-machine ip node-1)/"

curl "http://$(docker-machine ip node-1):8080/v1/docker-flow-proxy/config"

docker service update --publish-add 1234:80 laravel_app

docker service ps laravel_app # Wait until it's updated

curl "http://$(docker-machine ip node-1):1234"

You'll notice that the third command from the bottom exposes internal port 80 of your app as 1234. From that moment on, I should be able to send a request to your app on port 1234 and Docker would redirect it to internal port 80 (the same port you configured). The response from the last command (curl) is curl: (7) Failed to connect to 192.168.99.100 port 1234: Connection refuse.

In other words, your app inside the container is not listening to port 80 (with or without the proxy).

Can you send me the Dockerfile you used to build the container? Also, it would help if you could confirm that your application listens on port 80 (both with and without container).

Feel free to ping me on Skype (user: vfarcic) or HangOuts (user: viktor@farcic.com) and we can take a look at your application together.

shibli786 commented 7 years ago

Hi vfarcic, I created all images from docker-compose file then i committed all running containers. By the way i have checked the laravel_app container and came to know that it is not listening on the port 80 as you are saying because issue is with my improper configured container...

I am wondering how your proxy and consul are communicating with each other from an algorithm point of view documentation haven't throws light on it if you can explain it then it will be really owsome.

thanks for giving me your precious time.

jorgebo10 commented 6 years ago

Hi vfarcic, i'm having some problems while trying to configure the servicePath. While setting servicePath as root context (/) works fine, setting other than root context is not working for me. I've attached my example below. I was wondering if you could point me in the right direction to fix it.

Thanks, Jorge

git clone https://github.com/vfarcic/docker-flow-proxy.git

cd docker-flow-proxy

chmod +x scripts/swarm-cluster.sh

scripts/swarm-cluster.sh

eval $(docker-machine env node-1)

docker node ls

docker network create --driver overlay proxy

docker network create --driver overlay go-demo

docker service create --name api-informes-db \
    --network go-demo \
    mongo:3.2.10

docker service create --name api-informes \
    -e DATABASE_URL=api-informes-db \
    -e DATABASE_PORT=27017 \
    -e DATABASE_NAME=sistac \
    -e APP_PORT=8080 \
    --network go-demo \
    --network proxy \
    jorgebo10/api-informes:1.3

docker service create --name proxy \
    -p 80:80 \
    -p 443:443 \
    -p 8080:8080 \
    --network proxy \
    -e MODE=swarm \
    vfarcic/docker-flow-proxy

curl "http://$(docker-machine ip node-1):8080/v1/docker-flow-proxy/reconfigure?serviceName=api-informes&servicePath=/&port=8080"
curl "http://$(docker-machine ip node-1)/api/informes/1" # working ok

curl "http://$(docker-machine ip node-1):8080/v1/docker-flow-proxy/reconfigure?serviceName=api-informes&servicePath=/informes&port=8080"
curl "http://$(docker-machine ip node-1)/informes/api/informes/1" # not working anymore
vfarcic commented 6 years ago

@jorgebo10 In your examples, there is no service called laravel_app. Did you mix the commands you posted with those from the others' posts? Also, are you sure that laravel_app listens to both / and /informes paths? The command you used with result in DFP forwarding requests to laravel_app as they are. That means that, for example, a request /informes/api/informes/1 in DFP will be forwarded to /informes/api/informes/1 in laravel_app. Is that what the application expected? You can test it out easily by temporarily publishing a port on laravel_app and confirming that you can send a request to /informes/api/informes/1 directly. My suspicion is that you want to rewrite requests from /informes/api/informes/1 in DFP to /api/informes/1 in laravel_app. Is that the case? If it is, can the service accept relative paths?

jorgebo10 commented 6 years ago

@vfarcic I've updated the serviceName as it was not correct. Thanks for pointing out that. The app listens only at / on port 8080. Your suspicion is right I would like to make use of the proxy to forward /informes/api/nformes => :8080/api/informes if this is possible. Thanks

vfarcic commented 6 years ago

You should add reqPathSearchReplace. For example:

curl "http://localhost:8080/v1/docker-flow-proxy/reconfigure?serviceName=api-informes&servicePath=/informes&port=8080&reqPathSearchReplace=/informes/,/"

Translated to plain words, it's forward all requests with paths starting with /informes. Before forwarding, it'll rewrite paths by replacing /informes/ with /.

Please let me know if that's what you were looking for.

jorgebo10 commented 6 years ago

Great that did the work. Thanks!