improve seperate log variable check
This commit is contained in:
parent
d3580cedf6
commit
3a6a46584d
3 changed files with 77 additions and 11 deletions
24
nginx.tmpl
24
nginx.tmpl
|
@ -107,6 +107,8 @@ map $scheme $proxy_x_forwarded_ssl {
|
|||
|
||||
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
{{ $seperate_logFiles := eq (or ($.Env.SEPERATE_LOGS_PER_VHOST) "") "true" }}
|
||||
|
||||
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
|
||||
'"$request" $status $body_bytes_sent '
|
||||
'"$http_referer" "$http_user_agent"';
|
||||
|
@ -257,7 +259,7 @@ server {
|
|||
listen [::]:{{ $external_http_port }} {{ $default_server }};
|
||||
{{ end }}
|
||||
|
||||
{{ if $.Env.SEPERATE_LOGS_PER_VHOST }}
|
||||
{{ if $seperate_logFiles }}
|
||||
access_log /var/log/nginx/{{ $host }}.access.log;
|
||||
error_log /var/log/nginx/{{ $host }}.error.log warn;
|
||||
{{ else }}
|
||||
|
@ -286,7 +288,7 @@ server {
|
|||
listen [::]:{{ $external_https_port }} ssl http2 {{ $default_server }};
|
||||
{{ end }}
|
||||
|
||||
{{ if $.Env.SEPERATE_LOGS_PER_VHOST }}
|
||||
{{ if $seperate_logFiles }}
|
||||
access_log /var/log/nginx/{{ $host }}.access.log;
|
||||
error_log /var/log/nginx/{{ $host }}.error.log warn;
|
||||
{{ else }}
|
||||
|
@ -389,7 +391,7 @@ server {
|
|||
listen [::]:80 {{ $default_server }};
|
||||
{{ end }}
|
||||
|
||||
{{ if $.Env.SEPERATE_LOGS_PER_VHOST }}
|
||||
{{ if $seperate_logFiles }}
|
||||
access_log /var/log/nginx/{{ $host }}.access.log;
|
||||
error_log /var/log/nginx/{{ $host }}.error.log warn;
|
||||
{{ else }}
|
||||
|
@ -468,11 +470,11 @@ server {
|
|||
listen [::]:{{ $external_https_port }} ssl http2 {{ $default_server }};
|
||||
{{ end }}
|
||||
|
||||
{{ if $.Env.SEPERATE_LOGS_PER_VHOST }}
|
||||
access_log /var/log/nginx/{{ $host }}.access.log;
|
||||
error_log /var/log/nginx/{{ $host }}.error.log warn;
|
||||
{{ if $seperate_logFiles }}
|
||||
access_log /var/log/nginx/{{ $host }}.access.log;
|
||||
error_log /var/log/nginx/{{ $host }}.error.log warn;
|
||||
{{ else }}
|
||||
access_log /var/log/nginx/access.log vhost;
|
||||
access_log /var/log/nginx/access.log vhost;
|
||||
{{ end }}
|
||||
|
||||
return 500;
|
||||
|
@ -537,7 +539,7 @@ server {
|
|||
listen [::]:80 {{ $default_server }};
|
||||
{{ end }}
|
||||
|
||||
{{ if $.Env.SEPERATE_LOGS_PER_VHOST }}
|
||||
{{ if $seperate_logFiles }}
|
||||
access_log /var/log/nginx/{{ $host_alias }}.access.log;
|
||||
error_log /var/log/nginx/{{ $host_alias }}.error.log warn;
|
||||
{{ else }}
|
||||
|
@ -554,7 +556,7 @@ server {
|
|||
listen [::]:443 ssl http2 {{ $default_server }};
|
||||
{{ end }}
|
||||
|
||||
{{ if $.Env.SEPERATE_LOGS_PER_VHOST }}
|
||||
{{ if $seperate_logFiles }}
|
||||
access_log /var/log/nginx/{{ $host_alias }}.access.log;
|
||||
error_log /var/log/nginx/{{ $host_alias }}.error.log warn;
|
||||
{{ else }}
|
||||
|
@ -604,7 +606,7 @@ server {
|
|||
listen [::]:80 {{ $default_server }};
|
||||
{{ end }}
|
||||
|
||||
{{ if $.Env.SEPERATE_LOGS_PER_VHOST }}
|
||||
{{ if $seperate_logFiles }}
|
||||
access_log /var/log/nginx/{{ $host_alias }}.access.log;
|
||||
error_log /var/log/nginx/{{ $host_alias }}.error.log warn;
|
||||
{{ else }}
|
||||
|
@ -633,7 +635,7 @@ server {
|
|||
listen [::]:443 ssl http2 {{ $default_server }};
|
||||
{{ end }}
|
||||
|
||||
{{ if $.Env.SEPERATE_LOGS_PER_VHOST }}
|
||||
{{ if $seperate_logFiles }}
|
||||
access_log /var/log/nginx/{{ $host_alias }}.access.log;
|
||||
error_log /var/log/nginx/{{ $host_alias }}.error.log warn;
|
||||
{{ else }}
|
||||
|
|
23
test/test_virtual_path.py
Normal file
23
test/test_virtual_path.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import pytest
|
||||
|
||||
|
||||
def test_default(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://nginx-proxy.test/port")
|
||||
assert r.status_code == 200
|
||||
assert r.text == "answer from port 81\n"
|
||||
|
||||
def test_simple_path(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://nginx-proxy.test/foo/port")
|
||||
assert r.status_code == 200
|
||||
assert r.text == "answer from port 82\n"
|
||||
|
||||
def test_deep_path(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://nginx-proxy.test/bar/even/deeper/port")
|
||||
assert r.status_code == 200
|
||||
assert r.text == "answer from port 83\n"
|
||||
|
||||
def test_closed_path(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://nginx-proxy.test/bar/even/deeper/with/end/port")
|
||||
assert r.status_code == 200
|
||||
assert r.text == "answer from port 84\n"
|
||||
|
41
test/test_virtual_path.yml
Normal file
41
test/test_virtual_path.yml
Normal file
|
@ -0,0 +1,41 @@
|
|||
web1:
|
||||
image: web
|
||||
expose:
|
||||
- "81"
|
||||
environment:
|
||||
WEB_PORTS: "81"
|
||||
VIRTUAL_HOST: "nginx-proxy.test"
|
||||
|
||||
web2:
|
||||
image: web
|
||||
expose:
|
||||
- "82"
|
||||
environment:
|
||||
WEB_PORTS: "82"
|
||||
VIRTUAL_HOST: "nginx-proxy.test"
|
||||
VIRTUAL_PATH: "/foo"
|
||||
|
||||
web3:
|
||||
image: web
|
||||
expose:
|
||||
- "83"
|
||||
environment:
|
||||
WEB_PORTS: "83"
|
||||
VIRTUAL_HOST: "nginx-proxy.test"
|
||||
VIRTUAL_PATH: "/bar/even/deeper"
|
||||
|
||||
web4:
|
||||
image: web
|
||||
expose:
|
||||
- "84"
|
||||
environment:
|
||||
WEB_PORTS: "84"
|
||||
VIRTUAL_HOST: "nginx-proxy.test"
|
||||
VIRTUAL_PATH: "/bar/even/deeper/with/end/"
|
||||
|
||||
|
||||
sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
Loading…
Reference in a new issue