Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 176417f

Browse files
committedMar 13, 2025
P7A-174: update configuration for a Node.js app
1 parent e378669 commit 176417f

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed
 

‎docs/source/macos/haproxy.rst

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,23 @@ Create configuration file ``/opt/local/etc/haproxy/haproxy.cfg`` with the follow
4242
bind *:443 ssl crt /Users/brodijak/ssl/chain.pem
4343
bind *:6443 ssl crt /Users/brodijak/ssl/chain.pem
4444
45+
acl is_node req.fhdr(Host),map_str(/opt/local/etc/haproxy/node_domains.map) -m found
46+
acl is_node_pass_through path_reg -i -f /opt/local/etc/haproxy/node_pass_through.patterns
47+
48+
http-request capture req.hdr(Host) len 128
49+
http-request capture req.fhdr(Referer) len 128
50+
4551
http-response set-header x-haproxy-frontend local
52+
http-request set-header x-forwarded-proto https if { ssl_fc }
53+
54+
option forwardfor
55+
56+
use_backend nginx if { path -m beg /.well-known/ } { dst_port 80 }
57+
use_backend nginx if { path -m beg /.well-known/ } { dst_port 443 }
58+
use_backend varnish if { path -m beg /.well-known/ } { dst_port 6080 }
59+
use_backend varnish if { path -m beg /.well-known/ } { dst_port 6443 }
60+
61+
use_backend node if is_node !is_node_pass_through
4662
4763
use_backend nginx if { dst_port 80 }
4864
use_backend nginx if { dst_port 443 }
@@ -51,16 +67,66 @@ Create configuration file ``/opt/local/etc/haproxy/haproxy.cfg`` with the follow
5167
5268
default_backend nginx
5369
70+
backend node
71+
http-request set-dst-port req.fhdr(Host),map(/opt/local/etc/haproxy/node_ports.map)
72+
http-response set-header x-haproxy-backend node
73+
server node 127.0.0.1:0 maxconn 32
74+
5475
backend nginx
5576
http-response set-header x-haproxy-backend nginx
56-
server nginx 127.0.0.1:8080 maxconn 32
77+
server nginx 127.0.0.1:8080 maxconn 32
5778
5879
backend varnish
5980
http-response set-header x-haproxy-backend varnish
60-
server varnish 127.0.0.1:6081 maxconn 32
81+
server varnish 127.0.0.1:6081 maxconn 32
6182
6283
Make sure to adapt the paths to certificate chain file on your system.
6384

85+
Create domain map file ``/opt/local/etc/haproxy/node_domains.map`` with the following content:
86+
87+
.. code:: console
88+
89+
# Contains a list of domains handled by Node.js, mapped to a corresponding domain
90+
# handled by Varnish/PHP:
91+
92+
node.pro.dev.php82.ez pro.dev.php82.ez
93+
us.node.pro.dev.php82.ez us.pro.dev.php82.ez
94+
95+
Create port map file ``/opt/local/etc/haproxy/node_domains.map`` with the following content:
96+
97+
.. code:: console
98+
99+
# Contains a list of domains handled by Node.js, mapped to a corresponding port
100+
# on which Node.js app is running:
101+
102+
node.pro.dev.php82.ez 3000
103+
us.node.pro.dev.php82.ez 3000
104+
105+
Create file containing pass-through patterns ``/opt/local/etc/haproxy/node_pass_through.patterns``
106+
with the following content:
107+
108+
.. code:: console
109+
110+
# Contains regular expression patterns to match URLs that are found on Node.js domains,
111+
# but should be handled by Varnish/PHP instead of Node.js (passed through to PHP)
112+
113+
# API endpoints
114+
^/(en/|fr/|de/|hr/)?(api|ngopenapi)
115+
116+
# Admin
117+
^/adminui
118+
119+
# Assets
120+
^/bundles
121+
^/assets
122+
123+
# Debug
124+
^/_wdt
125+
126+
# Sitemaps and robots.txt
127+
^/sitemap/.*
128+
^/robots.txt
129+
64130
3 Start
65131
-------
66132

0 commit comments

Comments
 (0)
Failed to load comments.