I'm having issues with getting a simple config to work with nginx. I have a server that host docker containers so nginx is in a container. So lets call the url foo.com
. I would like for the url foo.com/service1
to actually just go to foo.com on another port, so it would actually be pulling foo.com:4321
and foo.com/service2
to be pulling foo.com:5432
and so on. Here is the config I have been having issues with.
http { server { listen 0.0.0.0:80; location /service1/ { proxy_pass http://192.168.0.2:4321/; } location /service2/ { proxy_pass http://192.168.0.2:5432/; } } }
So the services and nginx live at 192.168.0.2. What is the prefered way to be able to do this? Thank you in advance!
As A side note, this is running in a docker container. Thanks!
4 Answers
Answers 1
http { server { listen 80; server_name foo.com; location /service1/ { proxy_pass http://192.168.0.2:4321/; } location /service2/ { proxy_pass http://192.168.0.2:5432/; } } }
Answers 2
I have a guess your problem is not related to Nginx per se, but instead it is related to Docker networking. You provided insufficient information to make a detailed conclusion, but here it is a couple of suggestions:
run a simple Docker container at the same host where nginx container is running and try
curl
from inside that container (I've seen your answer that you are able to callcurl
from the server running Nginx, but it's not really the same)for example, if the server running nginx container is OSX or Windows, it may use an intermediate Linux virtual machine with its own network stack, IP addreses, routing, etc.
Answers 3
This is my conf sending to inner glassfish. Check out the use of proxy_redirect off & proxy_set_header X-NginX-Proxy true;
#Glassfish location /MyService/ { index index.html; add_header Access-Control-Allow-Origin $http_origin; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-NginX-Proxy true; proxy_ssl_session_reuse off; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:18000/MyService/; }
Answers 4
I think you should check whether your foo.com
is pointing to the right ip address or not first by removing the reverse proxy config. E.g.
http { server { listen 80; server_name foo.com; location / { } } }
Then, if your ip
address already has a service running on port 80 you should specify the server_name
for each service like in my example. Nginx can only distinguish which service to respond to which domain by server_name
.
*My guess is that you forgot the server_name
option.
0 comments:
Post a Comment