I've been deploying Rocket onto EC2 AWS and I must say I'm impressed with the Rocket.toml as it's connecting to an RDS nicely. However, I am getting trouble with the routing. Using docker-compose, with other frameworks like Flask I usually get NGINX to route to the app by pointing it to the docker container name. In my NGINX conf I have the following:
location / {
proxy_pass http://rust_app:8000/;
}
rust_app is the name of the docker container. Again, this approach works with Flask on EC2. However, with Rocket I'm getting an upstream connection refused in the NGINX container:
/docker-entrypoint.sh: Configuration complete; ready for start up
2020/08/19 10:28:20 [error] 19#19: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 5.10.149.46, server: localhost, request: "GET /basic/token HTTP/1.1", upstream: "http://172.18.0.3:8000/basic/token", host: “52.14.254.244"
In my Rocket.toml I have the following configuration:
[production]
address = "127.0.0.1"
port = 8000
I have also tried this with the address of 172.18.0.3 as the error hints that this is being used. Is there any way we can configure the Rocket app in the accept incoming requests into its container from NGINX? I am exposing port 8000 in the Dockerfile for Rocket.
I have a similar docker container working just fine by binding to 0.0.0.0, have you tried that address?
[production]
address = "0.0.0.0"
port = 8000
@Nessex thanks it's now serving! However, whilst I can hit the home page, any mounted views I get with a URL extension such as "home_url/something/somethingelse" returns a resource not found 404 for NGINX. Did you get this and if so how did you fix it?
@maxwellflitton I have no idea if it matters but try removing the trailing / in proxy_pass after the port number.
@olback thanks for the suggestion. I didn't think of it. Sadly this didn't work, however.
This issue needs more information to be able to answer properly. In particular, any access or error logs from rocket and/or from nginx corresponding to these 404 requests would be a good starting point.
@jebrosen sorry for the late reply. I've done some builds and I realized I didn't register one of the views with the rocket app. All routes work with suggestion @Nessex made. When piping directly to a docker container through NGINX container having a location of 0.0.0.0 is needed. Thanks for your time guys. I appreciate it.
Looks like this has been resolved!