I have an Ubuntu VPS, and I have dockerized a simple Vue App, which is served by Nginx. I have set up SSL for it.
On same host, I have a container running Nodejs Express, which is routing simple queries to MySql database. Express is listening port 8080.
Everything works invidually - I can access the site with 443, and separately I can access the rest api with http://domain:8080 in Postman.
I have however been stuck with how to get Express to listen for https requests so I can use the rest api within the site.
Do I need another SSL cert for the Express? Or is enough if I bypass some url to the localhost:8080? Obviously I still want the site to be accessible with https://domain
What did I miss? Or did I miss it totally?
What I tried was something like:
location /api {
proxy_pass http://localhost:8080;
}
Within both 80 and 443 nginx listeners.
I however always get 502 badateway, if I try to access https://domain/api/foo. I expected it to return response from http://domain:8080/foo.
CodePudding user response:
What I was doing wrong was that the nginx container passed proxy to localhost, which of course I realized a bit late that was pointing to nginx container localhost, not the actual host.
I rewrote my compose.yml, the containers are now in the same network, which provides access to nodejs container in the nginx conf.
Now it works as expected.