Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Last active April 22, 2024 07:51
Show Gist options
  • Save bzdgn/6c648f91910be49e4a71b834e5f3b8bc to your computer and use it in GitHub Desktop.
Save bzdgn/6c648f91910be49e4a71b834e5f3b8bc to your computer and use it in GitHub Desktop.
Nginx Conf as Reverse Proxy for Keycloak
...
forwarder:
image: myngproxy:latest #coming from the local build docker image
ports:
- 9600:9600
links:
- keycloak:keycloak
networks:
- mystack-app-net
...
networks:
mystack-app-net:
driver: bridge
external: true
FROM nginx:latest
# Remove the default nginx configuration file
RUN rm /etc/nginx/conf.d/default.conf
# Copy a new configuration file from the current directory
COPY nginx.conf /etc/nginx/conf.d/
# Expose ports
EXPOSE 9600
# Start NGINX using the default command
CMD ["nginx", "-g", "daemon off;"]
# Build ngproxy before running dockerifle
# docker build -t myngproxy:latest .
server {
listen 9600;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://keycloak:9001/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment