mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Merge pull request #3069 from dokku/josegonzalez-patch-1
Remove potentially bad nginx template examples
This commit is contained in:
@@ -42,146 +42,6 @@ Dokku uses a templating library by the name of [sigil](https://github.com/glider
|
||||
|
||||
> Note: Application config variables are available for use in custom templates. To do so, use the form of `{{ var "FOO" }}` to access a variable named `FOO`.
|
||||
|
||||
### Example Custom Template
|
||||
|
||||
Use case: add an `X-Served-By` header to requests
|
||||
|
||||
```go
|
||||
server {
|
||||
listen [::]:{{ .NGINX_PORT }};
|
||||
listen {{ .NGINX_PORT }};
|
||||
server_name {{ .NOSSL_SERVER_NAME }};
|
||||
access_log /var/log/nginx/{{ .APP }}-access.log;
|
||||
error_log /var/log/nginx/{{ .APP }}-error.log;
|
||||
|
||||
# set a custom header for requests
|
||||
add_header X-Served-By www-ec2-01;
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1100;
|
||||
gzip_buffers 4 32k;
|
||||
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
|
||||
gzip_vary on;
|
||||
gzip_comp_level 6;
|
||||
|
||||
location / {
|
||||
proxy_pass http://{{ .APP }};
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Port $server_port;
|
||||
proxy_set_header X-Request-Start $msec;
|
||||
}
|
||||
include {{ .DOKKU_ROOT }}/{{ .APP }}/nginx.conf.d/*.conf;
|
||||
}
|
||||
|
||||
upstream {{ .APP }} {
|
||||
{{ range .DOKKU_APP_LISTENERS | split " " }}
|
||||
server {{ . }};
|
||||
{{ end }}
|
||||
}
|
||||
```
|
||||
|
||||
### Example HTTP to HTTPS Custom Template
|
||||
Use case: a simple dockerfile app that includes `EXPOSE 80`
|
||||
|
||||
```go
|
||||
server {
|
||||
listen [::]:80;
|
||||
listen 80;
|
||||
server_name {{ .NOSSL_SERVER_NAME }};
|
||||
|
||||
access_log /var/log/nginx/{{ .APP }}-access.log;
|
||||
error_log /var/log/nginx/{{ .APP }}-error.log;
|
||||
|
||||
return 301 https://$host:443$request_uri;
|
||||
}
|
||||
server {
|
||||
listen [::]:{{ $listen_port }} ssl {{ if eq $.HTTP2_SUPPORTED "true" }}http2{{ else if eq $.SPDY_SUPPORTED "true" }}spdy{{ end }};
|
||||
listen {{ $listen_port }} ssl {{ if eq $.HTTP2_SUPPORTED "true" }}http2{{ else if eq $.SPDY_SUPPORTED "true" }}spdy{{ end }};
|
||||
{{ if .NOSSL_SERVER_NAME }}server_name {{ .NOSSL_SERVER_NAME }}; {{ end }}
|
||||
{{ if .SSL_SERVER_NAME }}server_name {{ .SSL_SERVER_NAME }}; {{ end }}
|
||||
|
||||
access_log /var/log/nginx/{{ .APP }}-access.log;
|
||||
error_log /var/log/nginx/{{ .APP }}-error.log;
|
||||
|
||||
ssl_certificate {{ .APP_SSL_PATH }}/server.crt;
|
||||
ssl_certificate_key {{ .APP_SSL_PATH }}/server.key;
|
||||
|
||||
keepalive_timeout 70;
|
||||
add_header Alternate-Protocol 443:npn-spdy/2;
|
||||
location / {
|
||||
proxy_pass http://{{ .APP }};
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Port $server_port;
|
||||
proxy_set_header X-Request-Start $msec;
|
||||
}
|
||||
include {{ .DOKKU_ROOT }}/{{ .APP }}/nginx.conf.d/*.conf;
|
||||
}
|
||||
|
||||
upstream {{ .APP }} {
|
||||
{{ range .DOKKU_APP_LISTENERS | split " " }}
|
||||
server {{ . }};
|
||||
{{ end }}
|
||||
}
|
||||
```
|
||||
|
||||
### Example using new proxy port mapping
|
||||
|
||||
```go
|
||||
{{ range $port_map := .PROXY_PORT_MAP | split " " }}
|
||||
{{ $port_map_list := $port_map | split ":" }}
|
||||
{{ $scheme := index $port_map_list 0 }}
|
||||
{{ $listen_port := index $port_map_list 1 }}
|
||||
{{ $upstream_port := index $port_map_list 2 }}
|
||||
|
||||
server {
|
||||
listen [::]:{{ $listen_port }};
|
||||
listen {{ $listen_port }};
|
||||
server_name {{ $.NOSSL_SERVER_NAME }};
|
||||
access_log /var/log/nginx/{{ $.APP }}-access.log;
|
||||
error_log /var/log/nginx/{{ $.APP }}-error.log;
|
||||
|
||||
location / {
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1100;
|
||||
gzip_buffers 4 32k;
|
||||
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
|
||||
gzip_vary on;
|
||||
gzip_comp_level 6;
|
||||
|
||||
proxy_pass http://{{ $.APP }}-{{ $upstream_port }};
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Port $server_port;
|
||||
proxy_set_header X-Request-Start $msec;
|
||||
}
|
||||
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
|
||||
}
|
||||
|
||||
{{ range $upstream_port := $.PROXY_UPSTREAM_PORTS | split " " }}
|
||||
upstream {{ $.APP }}-{{ $upstream_port }} {
|
||||
{{ range $listeners := $.DOKKU_APP_LISTENERS | split " " }}
|
||||
{{ $listener_list := $listeners | split ":" }}
|
||||
{{ $listener_ip := index $listener_list 0 }}
|
||||
server {{ $listener_ip }}:{{ $upstream_port }};{{ end }}
|
||||
}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
### Customizing via configuration files included by the default templates
|
||||
|
||||
The default nginx.conf template will include everything from your apps `nginx.conf.d/` subdirectory in the main `server {}` block (see above):
|
||||
|
||||
Reference in New Issue
Block a user