I am using a Docker container with an image based on python:2.7-alpine
.
I would like to have all the requests to ec2.us-west-2.amazonaws.com
to be redirected to 127.0.0.1:3000
.
How can I achieve that?
I am running a dummy AWS API endpoint locally in the container and I would like that all the requests to AWS EC2 go to my dummy endpoint on port 3000. Unfortunately, I cannot override the API endpoint, that is the reason because I am after a solution that may include IP tables and some hacks in the hosts file.
Asked
Active
Viewed 1,608 times
1

cloudy_weather
- 111
- 3
-
Plenty of web servers or reverse proxies can handle this, lighttpd, nginx, haproxy, to name a german couple. – Gerard H. Pille Jun 20 '18 at 09:57
-
ok are you able to show me an example of docker file using iptables? @GerardH.Pille – cloudy_weather Jun 20 '18 at 12:33
-
No, I meant to say that I would not use iptables to solve your problem. – Gerard H. Pille Jun 20 '18 at 14:10
-
Ok, can you show me how you would solve this problem in a Docker file? – cloudy_weather Jun 20 '18 at 14:36
1 Answers
0
To let nginx act as a reverse proxy for your Docker container, you'd add the following to its config
server {
server_name ec2.us-west-2.amazonaws.com;
location / {
proxy_pass_header Authorization;
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
client_max_body_size 0;
proxy_read_timeout 36000s;
proxy_redirect off;
}
}
If you'd like to know what you're doing, have a look at https://www.techandme.se/set-up-nginx-reverse-proxy/

Gerard H. Pille
- 2,569
- 1
- 13
- 11