Skip to content

Commit

Permalink
Allow redirects.s
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-de-bock committed Dec 19, 2024
1 parent c959a76 commit 63c6e9e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ This example is taken from [`molecule/default/converge.yml`](https://github.com/
- name: my_location
location: /my_location
backend_url: "http://localhost:8080/myapplication"
httpd_vhosts:
- name: redirect_to_https
servername: www.example.com
port: 8080
redirect_to_https: true
ssl_port: 8443
# httpd_vhosts:
# - name: my_vhost_docroot
# servername: www1.example.com
Expand Down
6 changes: 6 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
- name: my_location
location: /my_location
backend_url: "http://localhost:8080/myapplication"
httpd_vhosts:
- name: redirect_to_https
servername: www.example.com
port: 8080
redirect_to_https: true
ssl_port: 8443
# httpd_vhosts:
# - name: my_vhost_docroot
# servername: www1.example.com
Expand Down
14 changes: 13 additions & 1 deletion templates/vhost.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@
</IfModule>
{% endif %}

<VirtualHost *:{{ httpd_port }}>
{% if item.redirect_to_https is defined and item.redirect_to_https %}
<IfModule !rewrite_module>
LoadModule rewrite_module {{ httpd_modules_path }}/mod_rewrite.so
</IfModule>
{% endif %}

<VirtualHost *:{{ item.port | default(httpd_port) }}>
ServerName {{ item.servername }}

{% if item.serveralias is defined %}
ServerAlias {{ item.serveralias | join(' ') }}
{% endif %}

{% if item.redirect_to_https is defined and item.redirect_to_https %}
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}:{{ item.ssl_port | default(httpd_ssl_port) }}%{REQUEST_URI} [L,R=301]
{% else %}
{% if item.options is defined %}
Options {{ item.options|join(' ') }}
{% endif %}
Expand Down Expand Up @@ -48,4 +59,5 @@ ProxyPass / {{ item.backend_url }}
SetEnv {{ env.name }} {{ env.value | default("") }}
{% endfor %}
{% endif %}
{% endif %}
</VirtualHost>

0 comments on commit 63c6e9e

Please sign in to comment.