File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { migrate as logger } from "../logger.js" ;
2+
3+ const migrateName = "trust_forwarded_proto" ;
4+
5+ /**
6+ * Migrate
7+ *
8+ * @see http://knexjs.org/#Schema
9+ *
10+ * @param {Object } knex
11+ * @returns {Promise }
12+ */
13+ const up = function ( knex ) {
14+ logger . info ( `[${ migrateName } ] Migrating Up...` ) ;
15+
16+ return knex . schema
17+ . alterTable ( 'proxy_host' , ( table ) => {
18+ table . tinyint ( 'trust_forwarded_proto' ) . notNullable ( ) . defaultTo ( 0 ) ;
19+ } )
20+ . then ( ( ) => {
21+ logger . info ( `[${ migrateName } ] proxy_host Table altered` ) ;
22+ } ) ;
23+ } ;
24+
25+ /**
26+ * Undo Migrate
27+ *
28+ * @param {Object } knex
29+ * @returns {Promise }
30+ */
31+ const down = function ( knex ) {
32+ logger . info ( `[${ migrateName } ] Migrating Down...` ) ;
33+
34+ return knex . schema
35+ . alterTable ( 'proxy_host' , ( table ) => {
36+ table . dropColumn ( 'trust_forwarded_proto' ) ;
37+ } )
38+ . then ( ( ) => {
39+ logger . info ( `[${ migrateName } ] proxy_host Table altered` ) ;
40+ } ) ;
41+ } ;
42+
43+ export { up , down } ;
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ const boolFields = [
2121 "enabled" ,
2222 "hsts_enabled" ,
2323 "hsts_subdomains" ,
24+ "trust_forwarded_proto" ,
2425] ;
2526
2627class ProxyHost extends Model {
Original file line number Diff line number Diff line change 2222 " enabled" ,
2323 " locations" ,
2424 " hsts_enabled" ,
25- " hsts_subdomains"
25+ " hsts_subdomains" ,
26+ " trust_forwarded_proto"
2627 ],
2728 "properties" : {
2829 "id" : {
141142 "hsts_subdomains" : {
142143 "$ref" : " ../common.json#/properties/hsts_subdomains"
143144 },
145+ "trust_forwarded_proto" :{
146+ "type" : " boolean" ,
147+ "description" : " Trust the forwarded headers" ,
148+ "example" : false
149+ },
144150 "certificate" : {
145151 "oneOf" : [
146152 {
Original file line number Diff line number Diff line change 5858 "enabled" : true ,
5959 "locations" : [],
6060 "hsts_enabled" : false ,
61- "hsts_subdomains" : false
61+ "hsts_subdomains" : false ,
62+ "trust_forwarded_proto" : false
6263 }
6364 ]
6465 }
Original file line number Diff line number Diff line change 5656 "locations" : [],
5757 "hsts_enabled" : false ,
5858 "hsts_subdomains" : false ,
59+ "trust_forwarded_proto" : false ,
5960 "owner" : {
6061 "id" : 1 ,
6162 "created_on" : " 2025-10-28T00:50:24.000Z" ,
Original file line number Diff line number Diff line change 5656 "hsts_subdomains" : {
5757 "$ref" : " ../../../../components/proxy-host-object.json#/properties/hsts_subdomains"
5858 },
59+ "trust_forwarded_proto" : {
60+ "$ref" : " ../../../../components/proxy-host-object.json#/properties/trust_forwarded_proto"
61+ },
5962 "http2_support" : {
6063 "$ref" : " ../../../../components/proxy-host-object.json#/properties/http2_support"
6164 },
122125 "locations" : [],
123126 "hsts_enabled" : false ,
124127 "hsts_subdomains" : false ,
128+ "trust_forwarded_proto" : false ,
125129 "owner" : {
126130 "id" : 1 ,
127131 "created_on" : " 2025-10-28T00:50:24.000Z" ,
Original file line number Diff line number Diff line change 4848 "hsts_subdomains" : {
4949 "$ref" : " ../../../components/proxy-host-object.json#/properties/hsts_subdomains"
5050 },
51+ "trust_forwarded_proto" : {
52+ "$ref" : " ../../../components/proxy-host-object.json#/properties/trust_forwarded_proto"
53+ },
5154 "http2_support" : {
5255 "$ref" : " ../../../components/proxy-host-object.json#/properties/http2_support"
5356 },
119122 "locations" : [],
120123 "hsts_enabled" : false ,
121124 "hsts_subdomains" : false ,
125+ "trust_forwarded_proto" : false ,
122126 "certificate" : null ,
123127 "owner" : {
124128 "id" : 1 ,
Original file line number Diff line number Diff line change 11{% if certificate and certificate_id > 0 -%}
22{% if ssl_forced == 1 or ssl_forced == true %}
33 # Force SSL
4+ {% if trust_forwarded_proto == true %}
5+ set $trust_forwarded_proto "T";
6+ {% else %}
7+ set $trust_forwarded_proto "F";
8+ {% endif %}
49 include conf.d/include/force-ssl.conf;
510{% endif %}
611{% endif %}
Original file line number Diff line number Diff line change @@ -5,9 +5,28 @@ if ($scheme = "http") {
55if ($request_uri = /.well-known/acme-challenge/test-challenge) {
66 set $test "${test}T";
77}
8+
9+ # Check if the ssl staff has been handled
10+ set $test_ssl_handled "";
11+ if ($trust_forwarded_proto = "") {
12+ set $trust_forwarded_proto "F";
13+ }
14+ if ($trust_forwarded_proto = "T") {
15+ set $test_ssl_handled "${test_ssl_handled}T";
16+ }
817if ($http_x_forwarded_proto = "https") {
18+ set $test_ssl_handled "${test_ssl_handled}S";
19+ }
20+ if ($http_x_forwarded_scheme = "https") {
21+ set $test_ssl_handled "${test_ssl_handled}S";
22+ }
23+ if ($test_ssl_handled = "TSS") {
24+ set $test_ssl_handled "TS";
25+ }
26+ if ($test_ssl_handled = "TS") {
927 set $test "${test}S";
1028}
29+
1130if ($test = H) {
1231 return 301 https://$host$request_uri;
1332}
Original file line number Diff line number Diff line change 11add_header X-Served-By $host;
22proxy_set_header Host $host;
3- proxy_set_header X-Forwarded-Scheme $scheme ;
4- proxy_set_header X-Forwarded-Proto $scheme ;
3+ proxy_set_header X-Forwarded-Scheme $x_forwarded_scheme ;
4+ proxy_set_header X-Forwarded-Proto $x_forwarded_proto ;
55proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
66proxy_set_header X-Real-IP $remote_addr;
77proxy_pass $forward_scheme://$server:$port$request_uri;
You can’t perform that action at this time.
0 commit comments