diff --git a/templates/etc/nginx/sites-available/_base.j2 b/templates/etc/nginx/sites-available/_base.j2 index d416ace..c91e2b3 100644 --- a/templates/etc/nginx/sites-available/_base.j2 +++ b/templates/etc/nginx/sites-available/_base.j2 @@ -28,7 +28,7 @@ server { listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %}; {% endfor %} server_name {{ name }}; - return 301 https://{{ name }}{% if '443' not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri; + return 301 https://{{ name }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri; } {% endmacro %} diff --git a/tests/test.yml b/tests/test.yml index e922aeb..bf5b508 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -215,6 +215,7 @@ - name: - 'test-ssl-redirect-many.local' - 'test-ssl-redirect-many2.local' + listen_ssl: [8443] proto: ['https'] template: '_base' ssl_name: 'test-ssl.local' @@ -381,16 +382,16 @@ - 'test-ssl-predeployed.local' - 'test-ssl.local' - name: -- VERIFY SSL REDIRECT -- - command: "curl -v --insecure -H 'Host: {{ item }}' http://127.0.0.1/" + command: "curl -v -H 'Host: {{ item.name }}' http://127.0.0.1/" changed_when: false register: sslredirok - failed_when: > - sslredirok.stderr.find('< Location') == -1 and - sslredirok.stderr.find('https://{{ item }}/') == -1 + failed_when: "'< Location: https://{{ item.name }}{{ ':' + item.port if item.port is defined else '' }}/' not in sslredirok.stderr" with_items: - - 'test-ssl-redirect.local' - - 'test-ssl-redirect-many.local' - - 'test-ssl-redirect-many2.local' + - name: 'test-ssl-redirect.local' + - name: 'test-ssl-redirect-many.local' + port: '8443' + - name: 'test-ssl-redirect-many2.local' + port: '8443' # -------------------------------- # Default vhosts