https://github.com/shepmaster/nginx-template-image
Allow Docker environment variables in nginx configuration files
https://github.com/shepmaster/nginx-template-image
Last synced: about 1 year ago
JSON representation
Allow Docker environment variables in nginx configuration files
- Host: GitHub
- URL: https://github.com/shepmaster/nginx-template-image
- Owner: shepmaster
- License: mit
- Created: 2014-04-26T15:15:56.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-11-10T19:42:53.000Z (over 11 years ago)
- Last Synced: 2025-03-18T04:52:14.068Z (over 1 year ago)
- Language: Shell
- Size: 217 KB
- Stars: 38
- Watchers: 5
- Forks: 20
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nginx-template-image
This container allows you to use the environment variables set by a
Docker link inside of your nginx configuration.
## Usage
Mount your configuration to `/etc/nginx/sites-templates`, preferably
read-only. To capture logs, mount a writable directory to
`/var/log/nginx`.
Both HTTP (80) and HTTPS (443) ports are exposed.
For example:
```
docker run \
--publish 8080:80 \
--publish 8443:443 \
--volume /tmp/nginx-config:/etc/nginx/sites-templates:ro \
--volume /tmp/nginx-logs:/var/log/nginx \
--link my-rails-app:rails \
shepmaster/nginx-template-image
```
### Example nginx config
This is just an example of how to use the templating with a linked
container named `rails`, and should not be treated as an nginx
configuration guide!
```
# mount this as /etc/nginx/sites-templates/cool-app.conf.tmpl
# will be available as /etc/nginx/sites-enabled/cool-app.conf
server {
listen 80;
server_name my-cool-app.dev;
location / {
if (!-f $request_filename) {
proxy_pass http://${RAILS_PORT_3000_TCP_ADDR}:${RAILS_PORT_3000_TCP_PORT};
break;
}
}
}
```
## Further information
### Environment variables
Docker links are communicated via environment variables, but nginx
does not easily allow environment variables in configuration files.
To work around this, configuration files mounted at
`/etc/nginx/sites-templates` will be copied to
`/etc/nginx/sites-enabled`. Any file that ends with `.tmpl` will have
variable references like `${FOO}` replaced with the corresponding
environment variable and have the `.tmpl` suffix removed.
### Only include .conf files
The default nginx configuration includes all files in `sites-enabled`,
which makes it difficult to have supplemental files like SSL keys in
the same directory. This container will only load files that end in
`.conf`.