last day (19 days later) » 

10:30 PM
0
Q: Running TomEE API in Docker container successful, but reverse proxy returns a 404

King ReloadSo what I am trying to do is to have multiple Tomcat (TomEE) instances running in Docker containers. Then to reverse proxy into one of these containers to return the correct data. It tells me that the TomEE instance has started, but on the browser it still returns a 404 error. Using CATALINA_BASE...

 
@rzo1 good point, the proxy seems to reach the container though, so I don't think it works without the proxy neither. Sadly I cannot really completely test that theory, but it would be a problem with the way that the dockerfile or maven are set up then, though its still strange that the tomcat server runs, but doesn't do anything. I'm honestly just confused, I'll try to see if I can test the tomee container without a proxy and I'll get back to you if I got the answer
@rzo1 Error deploying web application archive [/workspace/tomee/webapps/example.war] I assume this is because of a version issue, but I honestly don't know what it should be, since there's so little documentation on how to configure TomEE with Maven Java. So it is probably the Dockerfile that needs different versions of TomEE or maven / java
@rzo1 ok, so there was indeed a version problem in the dockerfile, however now that it is fixed and running, it still gives me the 404 error. This time the local docker container on my machine with the image of the backend is correctly running, when I start up the frontend and send a request, it gives me a CORS problem, even though I allowed the correct headers in the backend. However on the production side it does not give me CORS problems, but it still does give me the 404 error.
@rzo1 I know why it gave me CORS problems on the local machine and that's not the problem anymore, its reacting to the frontend now, but the production version still gives that 404 error and I cannot seem to figure why
 
Your setup looks fine. Have you tried to access the web application in your container directly, without the proxy I mean? Did it work? What technology (docker-compose, etc) are you using in your deployment? Please, could you provide more information about that?
 
@jccampanero the curl request that I send to the docker container returns a 404 actually, but it also contains html and css, I put it in the question
 
Thank you very much for the feedback @KingReload. Well, if you routed your request via port 8080 and it actually returns a Tomcat error page it means several things: one, that Tomcat is running, and two, that the problem has nothing to do with the proxy but with Tomcat or probably the application itself; if the problem was related to the proxy the request via port 8080 would probably have been successful. Are there any errors in the log files?
The logs you showed in the question clearly indicates that the application was deployed successfully indeed.
 
@jccampanero there are no errors in the logs, I even tried deploying it on a local docker container, an error did appear there, but I already solved that one as well, which was the versioning issue I mentioned with rzo1
@TheFunk good thing is that the prefix on the proxy is also the path that I need on the backend :> since it's example.com/example/home and the prefix in the proxy is /example, not sure though if it does a example.com/example/example/home though
 
10:30 PM
I see @KIngReload. I just deployed a local docker container using your Dockerfile using a war with basically a welcome file index.html and it worked properly. This is why I think the error should be related to your application. Are you using some kind of Tomcat specific configuration? I mean, something like a Context, detasource, etcetera.
 
@jccampanero yeah that works for me as well, but for some reason on production it doesn't-
 
And which is the difference between your local environment and the production one, regarding docker I mean? If you are using docker, the same image should work properly in both environments
 
@jccampanero there is no difference between the docker containers, which is why I am so confused to why I'm getting a 404
 
Could be the home path the problem? Did you try to point your app to http://<your-server>:8080/example/? Does the browser indicate any redirection in the dev tools?
 
@jccampanero the /? adds the home path behind the request? I am very inexperienced with nginx... all I have tried is in the nginx.conf within the question
 
10:30 PM
Hi mate
No @KingReload, sorry if I confused you. You should try just http://<your-server>:8080/example/
 
hey!
 
nice to meet you
 
likewise! and I'll try see if that changes anything, since the request itself needs to still contain the /example/<whatever path is here>
 
please, try the path you consider necessary
 
also, should I apply the /example/ in the upstream or where I proxy to the upstream?
 
10:33 PM
no, you nginx configuration is fine like you posted in your question
just be aware of the following
when you point your request to http://<your-server>:8080/example/ or http://<your-server>:8080/example/home using port 8080 you are contacting Tomcat directly
if you want to use nginx you need to point your request to port 80, http://<your-server>:80/example/ or just http://<your-server>/example/
in fact, thinking about it, it could be the issue
 
yeah I've had issues with that in the previous question I managed to answer myself
I had to point to 8080 for it to reach the container
 
by default, when you deploy the app in tomcat like example.war it associates the app the /example context path
 
yeah that's why the .war is called example.war
 
but in your nginx you are indicating as well the everything over /example should be to your upstream :8080
 
and why in nginx.conf the path it refers to is also /example
 
10:37 PM
exactly
but perhaps the context is duplicated
 
yeah, since it can go to /example/home /example/etc
 
please, try the following: http://<your-server>/example/example/home
 
with a curl request you mean?
 
note the two /example
yes, please
 
same thing happens as in the question
same curl error
it shows the html stuff with 404 error pasted in it
 
10:41 PM
i see
 
can't send it here because it's too long
 
don't worry, please
I am sure the problem is related to the app
at least i think so
please, consider review again the tomcat logs
search for any error
related, for instance, with database connectivity
 
not sure how or where I should look, since it runs fine locally, even with a local docker container running, it does work (though it does not find the database which is understandable)
 
I think it would be very likely the cause of the issue
 
aha when you mention it, it did have database errors
 
10:43 PM
that is important
 
on the local environment
not on the production
however I am not sure how to connect to a database that is outside of a docker container
 
in the same way KingReload
 
I have as host for the database host.docker.internal
 
because the db is in you machine?
 
the database is in the VPS, but the VPS has the docker container with tomcat
but it couldn't reach the database before
since I tried connecting with localhost, however that was trying to find a database inside the docker container itself
 
10:46 PM
that is right
well, in any case, the strange thing is that in production in doesn't report errors
 
so the way I have host host.docker.internal instead of localhost is correct?
 
because it would make sense if the app is not starting correctly
host.docker.internal is an alias for the host that is serving your container
the one in which docker is installed
 
I'll update the logs in the question
 
ok
thank you
on the other hand, localhost in your container refers to the own container address
 
Body is limited to 30000 characters; you entered 31080.
stackoverflow error
 
10:50 PM
;)
please, be careful with the logs
be sure to not provide any sensitive information within them
@KingReload It is quite late here, I live in CET
 
I live in EU, its 1 AM haha
 
I will try to review your edits tomorrow
me too!
I will try reviewing your edits tomorrow
please, sorry
 
updated the logs
 
thank you
 
also no problem, I'll see tomorrow then!
 
10:54 PM
see you tomorrow mate
have a good night
 
you too!
 

  last day (19 days later) »