-
Notifications
You must be signed in to change notification settings - Fork 5
/
default.j2.conf
127 lines (108 loc) · 3.72 KB
/
default.j2.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# drop all unknown domains
server {
listen 80 default_server;
return 444;
}
{% if ProxyUseSSL == 'true' -%}
{% if ProxyForceHTTPS == 'true' -%}
# force redirect to HTTPS
server {
listen 80;
location / {
return 301 https://$host$request_uri;
}
}
{%- endif %}
# drop all unknown domains (SSL)
server {
listen 443 ssl default_server;
ssl_certificate /etc/nginx/certs/{{ ProxySSLCertName }};
ssl_certificate_key /etc/nginx/certs/{{ ProxySSLKeyName }};
return 444;
}
{%- endif %}
# a basic ngrok HTTP proxy
server {
server_name localhost {{ ProxyHostREST }};
{% if ProxyForceHTTPS != 'true' -%}
listen 80;
{%- endif %}
{% if ProxyUseSSL == 'true' -%}
listen 443 ssl;
ssl_certificate /etc/nginx/certs/{{ ProxySSLCertName }};
ssl_certificate_key /etc/nginx/certs/{{ ProxySSLKeyName }};
{%- endif %}
location / {
# the following line does the actual trick
proxy_set_header ngrok-skip-browser-warning 1;
proxy_set_header X-Forwarded-For $proxy_protocol_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host {{ TargetHost }};
{% if AddHeaderAccessControlAllowOrigin != '' -%}
add_header Access-Control-Allow-Origin {{ AddHeaderAccessControlAllowOrigin }};
{%- endif %}
# setting $upstream variable allows to avoid start-up crash if host is not reachable
# https://stackoverflow.com/a/32846603/20085654
resolver 8.8.8.8 valid=30s;
set $upstream {{ TargetScheme }}://{{ TargetHost }};
proxy_pass $upstream;
}
}
# ngrok proxy with WebSocket support
server {
server_name {{ ProxyHostWSSupport }};
{% if ProxyForceHTTPS != 'true' -%}
listen 80;
{%- endif %}
{% if ProxyUseSSL == 'true' -%}
listen 443 ssl;
ssl_certificate /etc/nginx/certs/{{ ProxySSLCertName }};
ssl_certificate_key /etc/nginx/certs/{{ ProxySSLKeyName }};
{%- endif %}
location / {
proxy_set_header ngrok-skip-browser-warning 1;
proxy_set_header X-Forwarded-For $proxy_protocol_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host {{ TargetHost }};
# https://www.nginx.com/blog/websocket-nginx/
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
{% if AddHeaderAccessControlAllowOrigin != '' -%}
add_header Access-Control-Allow-Origin {{ AddHeaderAccessControlAllowOrigin }};
{%- endif %}
resolver 8.8.8.8 valid=30s;
set $upstream {{ TargetScheme }}://{{ TargetHost }};
proxy_pass $upstream;
}
}
# ngrok proxy with SSE support
server {
server_name {{ ProxyHostSSESupport }};
{% if ProxyForceHTTPS != 'true' -%}
listen 80;
{%- endif %}
{% if ProxyUseSSL == 'true' -%}
listen 443 ssl;
ssl_certificate /etc/nginx/certs/{{ ProxySSLCertName }};
ssl_certificate_key /etc/nginx/certs/{{ ProxySSLKeyName }};
{%- endif %}
location / {
proxy_set_header ngrok-skip-browser-warning 1;
proxy_set_header X-Forwarded-For $proxy_protocol_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host {{ TargetHost }};
# https://stackoverflow.com/a/13673298/20085654
proxy_http_version 1.1;
proxy_set_header Connection '';
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
{% if AddHeaderAccessControlAllowOrigin != '' -%}
add_header Access-Control-Allow-Origin {{ AddHeaderAccessControlAllowOrigin }};
{%- endif %}
resolver 8.8.8.8 valid=30s;
set $upstream {{ TargetScheme }}://{{ TargetHost }};
proxy_pass $upstream;
}
}