Skip to content

Commit

Permalink
WIP: Add a reverse proxy template
Browse files Browse the repository at this point in the history
After asking in weareinteractive#11 I decided to just publish my config to help others easily
deploy a reverse proxy.
  • Loading branch information
goetzk committed May 9, 2020
1 parent 4d4c075 commit b63e8f0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Here is a list of all the default variables for this role, which are also availa
# name: foo
# file: foo
# append: ''
# proxy_pass:
# - target: 127.0.0.1
# - target_port: 8000
#
# dependencies packages to install package
Expand Down
46 changes: 46 additions & 0 deletions templates/etc/nginx/sites-available/reverse-proxy.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# {{ ansible_managed }}

# HTTPS terminating proxy sitting in front of webapp.

# TODO: Check: Some of this file can probably be removed with no loss in functionality.

# default_server on listen is required to work around bug https://github.com/certbot/certbot/issues/5817#issuecomment-391051737
server {
server_name {{ item.name }}{% for value in item.aliases|default([]) %} {{ value }}{% endfor %};

return 301 https://$host$request_uri;

listen 80 ;
return 404;
}

server {
server_name {{ item.name }}{% for value in item.aliases|default([]) %} {{ value }}{% endfor %};

charset utf-8;
keepalive_timeout {{ nginx_keepalive_timeout }};
client_max_body_size 128M;
gzip_types text/css application/javascript text/javascript text/plain text/xml application/xml;
gzip_vary on;

root {{ item.webroot }};

# Letsencrypt
location /.well-known {
alias {{ item.wellknown }}/.well-known;
}

location / {
proxy_pass http://{{ item.proxy_pass.target }}:{{ item.proxy_pass.target_port }}/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

listen 443 ssl;
ssl_certificate {{ item.ssl.cert_path |default(openssl_certs_path) }}/{{ item.ssl.cert_name|default('server.crt') }};
ssl_certificate_key {{ item.ssl.cert_path |default(openssl_keys_path) }}/{{ item.ssl.key_name|default('server.key') }};

}

0 comments on commit b63e8f0

Please sign in to comment.