diff --git a/nginx.tmpl b/nginx.tmpl index c16b477..e8e36ac 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -284,9 +284,18 @@ server { location / { {{ if (hasPrefix "www." $host) }} - return 301 https://{{ trimPrefix "www." $host }}$request_uri; - {{ else }} + # Redirect www. to non-www. + {{ $trimmedHost := trimPrefix "www." $host }} + {{ if eq $external_https_port "443" }} + return 301 https://{{ $trimmedHost }}$request_uri; + {{ else }} + return 301 https://{{ $trimmedHost }}:{{ $external_https_port }}$request_uri; + {{ end }} + {{ end }} + {{ if eq $external_https_port "443" }} return 301 https://$host$request_uri; + {{ else }} + return 301 https://$host:{{ $external_https_port }}$request_uri; {{ end }} } } diff --git a/test/pytest.sh b/test/pytest.sh index b1514bf..28275e5 100755 --- a/test/pytest.sh +++ b/test/pytest.sh @@ -18,8 +18,8 @@ docker build -t nginx-proxy-tester -f "${DIR}/requirements/Dockerfile-nginx-prox # run the nginx-proxy-tester container setting the correct value for the working dir in order for # docker-compose to work properly when run from within that container. -exec docker run --rm \ - -v ${DIR}:/${DIR} \ - -w ${DIR} \ - -v /var/run/docker.sock:/var/run/docker.sock \ - nginx-proxy-tester ${ARGS} +exec docker run --rm -it --name "nginx-proxy-pytest" \ + --volume "/var/run/docker.sock:/var/run/docker.sock" \ + --volume "${DIR}:${DIR}" \ + --workdir "${DIR}" \ + nginx-proxy-tester "${ARGS[@]}" \ No newline at end of file diff --git a/test/test_ssl/test_dhparam_generation.py b/test/test_ssl/test_dhparam_generation.py deleted file mode 100644 index 1e5d154..0000000 --- a/test/test_ssl/test_dhparam_generation.py +++ /dev/null @@ -1,44 +0,0 @@ -import backoff -import docker - -docker_client = docker.from_env() - - -############################################################################### -# -# Tests helpers -# -############################################################################### - -@backoff.on_exception(backoff.constant, AssertionError, interval=2, max_tries=15, jitter=None) -def assert_log_contains(expected_log_line): - """ - Check that the nginx-proxy container log contains a given string. - The backoff decorator will retry the check 15 times with a 2 seconds delay. - - :param expected_log_line: string to search for - :return: None - :raises: AssertError if the expected string is not found in the log - """ - sut_container = docker_client.containers.get("nginxproxy") - docker_logs = sut_container.logs(stdout=True, stderr=True, stream=False, follow=False) - assert expected_log_line in docker_logs - - -############################################################################### -# -# Tests -# -############################################################################### - -def test_dhparam_is_generated_if_missing(docker_compose): - sut_container = docker_client.containers.get("nginxproxy") - assert sut_container.status == "running" - - assert_log_contains("A pre-generated dhparam.pem will be used for now") - assert_log_contains("dhparam generation complete, reloading nginx") - - # Make sure the dhparam in use is not the default, pre-generated one - default_checksum = sut_container.exec_run("md5sum /app/dhparam.pem.default").split() - generated_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").split() - assert default_checksum[0] != generated_checksum[0] diff --git a/test/test_www_redirect.yml b/test/test_www_redirect.yml index 3bb2831..66da08a 100644 --- a/test/test_www_redirect.yml +++ b/test/test_www_redirect.yml @@ -22,6 +22,5 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./test_ssl/certs:/etc/nginx/certs:ro \ No newline at end of file