This is a setup you may need when developing locally with a different setup than the one you have in production:
- locally: client and server on different ports
- prod: client and server under the same origin
| docker build -t reverse-proxy . | |
| docker run -p 8080:80 --add-host host.docker.internal:host-gateway reverse-proxy |
| server { | |
| listen 80; | |
| server_name localhost; | |
| location / { | |
| root /usr/share/nginx/html; | |
| index index.html index.htm; | |
| proxy_pass http://host.docker.internal:3000; | |
| proxy_set_header Host $host; | |
| } | |
| location /proxy { | |
| return 302 /proxy/; | |
| } | |
| location /proxy/ { # trailing slash is important | |
| proxy_pass http://host.docker.internal:5000/; | |
| proxy_set_header Host $host; | |
| } | |
| error_page 500 502 503 504 /50x.html; | |
| location = /50x.html { | |
| root /usr/share/nginx/html; | |
| } | |
| } |
| FROM nginx:alpine | |
| WORKDIR /etc/nginx | |
| COPY ./default.conf ./conf.d/default.conf | |
| EXPOSE 80 | |
| ENTRYPOINT [ "nginx" ] | |
| CMD [ "-g", "daemon off;" ] |