Skip to content

Commit 334b9f7

Browse files
committed
nginx: configurable listen ip addresses
Based by idea of pikvm/pikvm#189
1 parent 6dea594 commit 334b9f7

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

configs/nginx/nginx.conf.mako

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ http {
3939
% if https_enabled:
4040

4141
server {
42-
listen ${http_port};
42+
listen ${http_ipv4}:${http_port};
4343
% if ipv6_enabled:
44-
listen [::]:${http_port};
44+
listen [${http_ipv6}]:${http_port};
4545
% endif
4646
include /etc/kvmd/nginx/certbot.ctx-server.conf;
4747
location / {
@@ -54,9 +54,9 @@ http {
5454
}
5555

5656
server {
57-
listen ${https_port} ssl;
57+
listen ${https_ipv4}:${https_port} ssl;
5858
% if ipv6_enabled:
59-
listen [::]:${https_port} ssl;
59+
listen [${https_ipv6}]:${https_port} ssl;
6060
% endif
6161
http2 on;
6262
include /etc/kvmd/nginx/ssl.conf;
@@ -67,9 +67,9 @@ http {
6767
% else:
6868

6969
server {
70-
listen ${http_port};
70+
listen ${http_ipv4}:${http_port};
7171
% if ipv6_enabled:
72-
listen [::]:${http_port};
72+
listen [${http_ipv6}]:${http_port};
7373
% endif
7474
include /etc/kvmd/nginx/certbot.ctx-server.conf;
7575
include /etc/kvmd/nginx/kvmd.ctx-server.conf;

kvmd/apps/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from ..validators.os import valid_options
7575
from ..validators.os import valid_command
7676

77+
from ..validators.net import valid_ip
7778
from ..validators.net import valid_ip_or_host
7879
from ..validators.net import valid_net
7980
from ..validators.net import valid_port
@@ -806,11 +807,15 @@ def _get_config_scheme() -> dict:
806807

807808
"nginx": {
808809
"http": {
809-
"port": Option(80, type=valid_port),
810+
"ipv4": Option("0.0.0.0", type=functools.partial(valid_ip, v6=False)),
811+
"ipv6": Option("::", type=functools.partial(valid_ip, v4=False)),
812+
"port": Option(80, type=valid_port),
810813
},
811814
"https": {
812-
"enabled": Option(True, type=valid_bool),
813-
"port": Option(443, type=valid_port),
815+
"enabled": Option(True, type=valid_bool),
816+
"ipv4": Option("0.0.0.0", type=functools.partial(valid_ip, v6=False)),
817+
"ipv6": Option("::", type=functools.partial(valid_ip, v4=False)),
818+
"port": Option(443, type=valid_port),
814819
},
815820
},
816821

kvmd/apps/ngxmkconf/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ def main(argv: (list[str] | None)=None) -> None:
5050
template = in_file.read()
5151

5252
rendered = mako.template.Template(template).render(
53+
http_ipv4=config.nginx.http.ipv4,
54+
http_ipv6=config.nginx.http.ipv6,
5355
http_port=config.nginx.http.port,
5456
https_enabled=config.nginx.https.enabled,
57+
https_ipv4=config.nginx.https.ipv4,
58+
https_ipv6=config.nginx.https.ipv6,
5559
https_port=config.nginx.https.port,
5660
ipv6_enabled=network.is_ipv6_enabled(),
5761
)

0 commit comments

Comments
 (0)