Skip to content

Commit a0b8e7e

Browse files
renovate[bot]Zoey2936
authored andcommitted
see commit body
improve configuration of static sites/php sites use reuseport and deferred for tcp binding dep updates Signed-off-by: Zoey <zoey@z0ey.de>
1 parent cf55e34 commit a0b8e7e

23 files changed

+167
-165
lines changed

README.md

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -144,45 +144,28 @@ labels:
144144
9. save the file
145145
10. redeploy the `compose.yaml`
146146

147-
# coreruleset plugins
148-
1. Download the plugin (all files inside the `plugins` folder of the git repo), most time: `<plugin-name>-before.conf`, `<plugin-name>-config.conf` and `<plugin-name>-after.conf` and sometimes `<plugin-name>.data` and/or `<plugin-name>.lua` or somilar files
149-
2. put them into the `/opt/npmplus/modsecurity/crs-plugins` folder
150-
3. maybe open the `/opt/npmplus/modsecurity/crs-plugins/<plugin-name>-config.conf` and configure the plugin
151-
152-
# Use as webserver
153-
1. Create a new Proxy Host
154-
2. Set `Scheme` to `https`, `Forward Hostname / IP` to `0.0.0.0`, `Forward Port` to `1` and enable `Websockets Support` (you can also use other values, since these get fully ignored)
155-
3. Maybe set an Access List
156-
4. Make your TLS Settings
157-
5.
158-
a) Custom Nginx Configuration (advanced tab), which looks the following for file server:
159-
- Note: the slash at the end of the file path is important
160-
```
161-
location / {
162-
alias /var/www/<your-html-site-folder-name>/;
163-
#fancyindex off; # alternative to nginx "index" option (looks better and has more options)
164-
}
165-
```
166-
b) Custom Nginx Configuration (advanced tab), which looks the following for file server and **php**:
167-
- Note: the slash at the end of the file path is important
168-
- Note: first enable `PHP82`, `PHP83` and/or `PHP84` inside your compose file
169-
- Note: you can replace `fastcgi_pass php82;` with `fastcgi_pass php83;`/`fastcgi_pass php84;`
170-
- Note: to add more php extension using envs you can set in the compose file
147+
## use of external php-fpm (recommended)
148+
1. Create a new Proxy Host with some dummy data for `Scheme` (like `path`), `Domain/IP/Path` (like `0.0.0.0`) (you can also use other values, since these get fully ignored)
149+
2. make other settings (like TLS)
150+
3. put this in the advanced tab and adjust:
171151
```
172152
location / {
173-
alias /var/www/<your-html-site-folder-name>/;
153+
alias /var/www/<your-html-site-folder-name>/; # or use the "root" directive of the line below
154+
#root /var/www/<your-html-site-folder-name>; # or use the "alias" directive of the line above
174155
#fancyindex off; # alternative to nginx "index" option (looks better and has more options)
175-
location ~ [^/]\.php(/|$) {
176-
fastcgi_pass php82;
177-
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
178-
if (!-f $document_root$fastcgi_script_name) {
179-
return 404;
180-
}
156+
location ~* \.php(?:$|/) {
157+
fastcgi_split_path_info ^(.*\.php)(/.*)$;
158+
try_files $fastcgi_script_name =404;
159+
fastcgi_pass ...; # set this to the address of your php-fpm
181160
}
182161
}
183162
```
184163

185-
# Load Balancing
164+
## use of inbuilt php-fpm (not recommended)
165+
1. first enable php inside your compose file (you can add more php extension using envs in the compose file)
166+
2. set the forwarding port to the php version you want to use and is supported by NPMplus (like 82/83/84)
167+
168+
## Load Balancing
186169
1. open and edit this file: `/opt/npmplus/custom_nginx/http_top.conf` (or `/opt/npmplus/custom_nginx/stream_top.conf` for streams), if you changed /opt/npmplus to a different path make sure to change the path to fit
187170
2. set the upstream directive(s) with your servers which should be load balanced (https://nginx.org/en/docs/http/ngx_http_upstream_module.html / https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html), they need to run the same protocol (either http or https or tcp/udp for streams), like this for example:
188171
```
@@ -324,6 +307,11 @@ proxy_set_header Content-Length "";
324307
14. I think this does not need to be mentioned, but you can mention it if you want to be sure (does not apply if you use letsencrypt, they don't support OCSP anymore): some clients (like firefox) send OCSP requests to your CA by default if the CA adds OCSP-URLs to your cert (can be disabled by the users in firefox), I think this does not need to be mentioned as no data goes to you, but directly to the CA and the client initiates this check by itself and is not ask or required by you to do this, your cert just says the the client can check this if it wants
325308
15. Also optional and should no be required, I think: some information about the data saved by the nameservers running your domain, should not be required I think, since nearly always there is a provider between the users and your nameserver which acts like a proxy so the dns requests of your users will be hidden as theier provider, which instead should explain theier users how they handle data as "dns proxy"
326309

310+
## coreruleset plugins
311+
1. Download the plugin (all files inside the `plugins` folder of the git repo), most time: `<plugin-name>-before.conf`, `<plugin-name>-config.conf` and `<plugin-name>-after.conf` and sometimes `<plugin-name>.data` and/or `<plugin-name>.lua` or somilar files
312+
2. put them into the `/opt/npmplus/modsecurity/crs-plugins` folder
313+
3. maybe open the `/opt/npmplus/modsecurity/crs-plugins/<plugin-name>-config.conf` and configure the plugin
314+
327315
## prerun scripts (EXPERT option) - if you don't know what this is, ignore it
328316
if you need to run scripts before NPMplus launches put them under: `/opt/npmplus/prerun/*.sh` (please add `#!/usr/bin/env sh` / `#!/usr/bin/env bash` to the top of the script) you need to create this folder yourself, also enable the env
329317

backend/internal/ip_ranges.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const internalIpRanges = {
104104
let template = null;
105105
const filename = '/tmp/ip_ranges.conf';
106106
try {
107-
template = fs.readFileSync('/app/templates/_ip_ranges.conf', { encoding: 'utf8' });
107+
template = fs.readFileSync('/app/templates/ip_ranges.conf', { encoding: 'utf8' });
108108
} catch (err) {
109109
reject(new error.ConfigurationError(err.message));
110110
return;

backend/internal/nginx.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const internalNginx = {
126126
let template;
127127

128128
try {
129-
template = fs.readFileSync('/app/templates/_location.conf', { encoding: 'utf8' });
129+
template = fs.readFileSync('/app/templates/_proxy_host_custom_location.conf', { encoding: 'utf8' });
130130
} catch (err) {
131131
reject(new error.ConfigurationError(err.message));
132132
return;
@@ -139,9 +139,8 @@ const internalNginx = {
139139
for (let i = 0; i < host.locations.length; i++) {
140140
const locationCopy = Object.assign({}, { access_list_id: host.access_list_id }, { certificate_id: host.certificate_id }, { ssl_forced: host.ssl_forced }, { caching_enabled: host.caching_enabled }, { block_exploits: host.block_exploits }, { allow_websocket_upgrade: host.allow_websocket_upgrade }, { http2_support: host.http2_support }, { hsts_enabled: host.hsts_enabled }, { hsts_subdomains: host.hsts_subdomains }, { access_list: host.access_list }, { certificate: host.certificate }, host.locations[i]);
141141

142-
if (locationCopy.forward_host.indexOf('/') > -1) {
142+
if (locationCopy.forward_host.indexOf('/') > -1 && !locationCopy.forward_host.startsWith('/') && !locationCopy.forward_host.startsWith('unix')) {
143143
const split = locationCopy.forward_host.split('/');
144-
145144
locationCopy.forward_host = split.shift();
146145
locationCopy.forward_path = `/${split.join('/')}`;
147146
}
@@ -206,7 +205,7 @@ const internalNginx = {
206205
locationsPromise = Promise.resolve();
207206
}
208207

209-
if (host.forward_host && host.forward_host.indexOf('/') > -1) {
208+
if (host.forward_host && host.forward_host.indexOf('/') > -1 && !host.forward_host.startsWith('/') && !host.forward_host.startsWith('unix')) {
210209
const split = host.forward_host.split('/');
211210

212211
host.forward_host = split.shift();

backend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"archiver": "7.0.1",
1111
"batchflow": "0.4.0",
1212
"bcrypt": "6.0.0",
13-
"better-sqlite3": "12.1.0",
13+
"better-sqlite3": "12.1.1",
1414
"body-parser": "2.2.0",
1515
"compression": "1.8.0",
1616
"express": "5.1.0",
@@ -37,9 +37,9 @@
3737
"@eslint/js": "9.29.0",
3838
"eslint": "9.29.0",
3939
"eslint-config-prettier": "10.1.5",
40-
"eslint-plugin-prettier": "5.5.0",
40+
"eslint-plugin-prettier": "5.5.1",
4141
"globals": "16.2.0",
42-
"prettier": "3.6.0"
42+
"prettier": "3.6.2"
4343
},
4444
"scripts": {
4545
"validate-schema": "node validate-schema.js"

backend/schema/components/proxy-host-object.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
},
8282
"forward_scheme": {
8383
"type": "string",
84-
"enum": ["http", "https", "grpc", "grpcs"]
84+
"enum": ["http", "https", "path", "grpc", "grpcs"]
8585
},
8686
"enabled": {
8787
"$ref": "../common.json#/properties/enabled"

backend/templates/_header_comment.conf

Lines changed: 0 additions & 4 deletions
This file was deleted.

backend/templates/_location.conf

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{% assign path_first_char = path | slice: 0 -%}
2+
3+
{% if path != "/" and path_first_char == "/" and path_last_char == "/" %}
4+
location {{ path | remove_last: "/" }} {
5+
absolute_redirect off;
6+
return 301 {{ path }};
7+
}
8+
{% endif %}
9+
10+
location {{ path }} {
11+
set $forward_scheme "{{ forward_scheme }}";
12+
set $server "{{ forward_host }}";
13+
set $port "{{ forward_port }}";
14+
set $forward_path "{{ forward_path }}";
15+
16+
{{ advanced_config }}
17+
18+
{% if forward_scheme == "http" or forward_scheme == "https" %}
19+
include conf.d/include/proxy-headers.conf;
20+
proxy_pass {{ forward_scheme }}://{{ forward_host }}{% if forward_port != null %}:{{ forward_port }}{% endif %}{% if forward_path != null %}{{ forward_path }}{% else %}$request_uri{% endif %};
21+
{% elsif forward_scheme == "grpc" or forward_scheme == "grpcs" %}
22+
include conf.d/include/grpc-headers.conf;
23+
grpc_pass {{ forward_scheme }}://{{ forward_host }}{% if forward_port != null %}:{{ forward_port }}{% endif %}{% if forward_path != null %}{{ forward_path }}{% else %}$request_uri{% endif %};
24+
{% elsif forward_scheme == "path" %}
25+
{% if forward_host_last_char == "/" %}
26+
alias {{ forward_host }};
27+
{% else %}
28+
root {{ forward_host }};
29+
{% endif %}
30+
{% if forward_path != null %}
31+
location ~* \.php(?:$|/) {
32+
fastcgi_split_path_info ^(.*\.php)(/.*)$;
33+
try_files $fastcgi_script_name =404;
34+
fastcgi_pass unix:/run/php{{ forward_port }}.sock;
35+
}
36+
{% endif %}
37+
{% endif %}
38+
}

backend/templates/dead_host.conf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{% include "_header_comment.conf" %}
1+
# ----------------------------------------------------------------------
2+
# {{ domain_names | join: ", " }}
3+
# DO NOT EDIT THIS FILE DIRECTLY, CHANGES WILL BE LOST WHEN UPDATING!
4+
# ----------------------------------------------------------------------
25

36
{% if enabled %}
47
server {

backend/templates/default.conf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# ------------------------------------------------------------
1+
# ----------------------------------------------------------------------
22
# Default Site
33
# DO NOT EDIT THIS FILE DIRECTLY, CHANGES WILL BE LOST WHEN UPDATING!
4-
# ------------------------------------------------------------
4+
# ----------------------------------------------------------------------
5+
56
server {
67
{% if env.DISABLE_HTTP == "false" %}
78
listen {{ env.IPV4_BINDING }}:{{ env.HTTP_PORT }}{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
@@ -24,12 +25,12 @@ server {
2425

2526
server {
2627
{% if env.DISABLE_HTTP == "false" %}
27-
listen {{ env.IPV4_BINDING }}:{{ env.HTTP_PORT }} default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
28-
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTP_PORT }} default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
28+
listen {{ env.IPV4_BINDING }}:{{ env.HTTP_PORT }} reuseport deferred default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
29+
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTP_PORT }} reuseport deferred default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
2930
{% endif %}
3031

31-
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} ssl default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
32-
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} ssl default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
32+
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} ssl reuseport deferred default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};
33+
{% if env.DISABLE_IPV6 == "false" %}listen {{ env.IPV6_BINDING }}:{{ env.HTTPS_PORT }} ssl reuseport deferred default_server{% if env.LISTEN_PROXY_PROTOCOL == "true" %} proxy_protocol{% endif %};{% endif %}
3334

3435
{% if env.DISABLE_H3_QUIC == "false" %}
3536
listen {{ env.IPV4_BINDING }}:{{ env.HTTPS_PORT }} quic reuseport default_server;

0 commit comments

Comments
 (0)