Created
October 10, 2018 16:54
-
-
Save nicholasjackson/743ec7ace01e9addc128601565b04ae7 to your computer and use it in GitHub Desktop.
Example using Consul Connect and Nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Consul connect and Nginx | |
## Example docker compose | |
```yaml | |
nginx: | |
image: nginx:latest | |
volumes: | |
- ./docker-compose-nginx.conf:/etc/nginx/nginx.conf:ro | |
ports: | |
- "8181:80" | |
depends_on: | |
- consul | |
nginx-proxy: | |
image: consul:latest | |
network_mode: "service:nginx" | |
entrypoint: "consul" | |
command: [ | |
'connect', | |
'proxy', | |
'-log-level=DEBUG', | |
'-service', 'nginx', | |
'-http-addr', 'consul:8500', | |
'-upstream', 'emojify-website:8000', | |
'-upstream', 'emojify-auth:8001' | |
] | |
environment: | |
- SERVICE_IGNORE=true | |
depends_on: | |
- consul | |
``` | |
## Example nginx config | |
``` | |
events { | |
worker_connections 1024; | |
} | |
http { | |
upstream emojify-website { | |
server localhost:8000; | |
} | |
upstream emojify-auth { | |
server localhost:8001; | |
} | |
server { | |
location / { | |
proxy_pass http://emojify-website; | |
proxy_set_header Host $host; | |
} | |
location ~ ^/auth(/?)(.*) { | |
proxy_pass http://emojify-auth/$2; | |
proxy_set_header Host $host; | |
proxy_set_header Origin http://localhost:8181; | |
proxy_pass_request_headers on; | |
} | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment