Skip to content

Commit c0cac35

Browse files
authored
Merge pull request #408 from ByteInternet/Add-document-How-to-set-up-an-application-proxy-in-Nginx
Add document "How to set up an application proxy in Nginx?"
2 parents 17631a9 + 6543557 commit c0cac35

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
myst:
3+
html_meta:
4+
description: Learn how to set up an Nginx application proxy on Hypernode using Managed Vhosts: create a proxy vhost and point it to your app
5+
title: How to set up an application proxy in Nginx? | Hypernode
6+
---
7+
8+
# How to Set Up an Application Proxy in Nginx
9+
10+
Sometimes you want to serve an application that listens on a local port (for example a Node, Python or PHP service on `localhost:3000`) behind a friendly domain on your Hypernode. Instead of writing a custom Nginx config, you can use Hypernode Managed Vhosts to generate a ready‑made proxy vhost coniguration and then just point it to your application. This keeps your configuration simple and consistent with the rest of your setup.
11+
12+
## Create a proxy vhost
13+
14+
Create a new vhost and set its type to `proxy`. In the example below we create a vhost for `proxy.myapp.hypernode.io`:
15+
16+
```console
17+
app@abc123-example-magweb-cmbl:~$ hmv proxy.myapp.hypernode.io --type proxy
18+
INFO: Managing configs for proxy.myapp.hypernode.io
19+
INFO: No existing config for proxy.myapp.hypernode.io, starting with default options
20+
INFO: Writing HTTP config for proxy.myapp.hypernode.io
21+
```
22+
23+
This command creates a vhost directory under `/data/web/nginx/<your-domain>/` with the proxy templates. You will see the following files:
24+
25+
```console
26+
app@abc123-example-magweb-cmbl:~/nginx/proxy.myapp.hypernode.io$ ls
27+
public.proxy.conf server.rewrites.conf staging.proxy.conf
28+
```
29+
30+
## Point the proxy to your application
31+
32+
Open `public.proxy.conf`. The only lines you normally need to change are at the top: the upstream host and port your application listens on. By default they point to `localhost:3000`.
33+
34+
```nginx
35+
set $app_proxy_host localhost;
36+
set $app_proxy_port 3000;
37+
38+
root /data/web/public;
39+
40+
include /etc/nginx/app_proxy_handler.conf;
41+
42+
location / {
43+
echo_exec @app_proxy_handler;
44+
}
45+
```
46+
47+
Replace `localhost` and `3000` with the correct target for your app if it listens elsewhere. You generally do not need to change anything below those two lines. The included `app_proxy_handler.conf` wires up sensible proxy defaults, SSL, headers and buffering for you. Save the file and Nginx will apply the change.
48+
49+
If you also plan to use the staging mode of this vhost, mirror the same host and port settings in `staging.proxy.conf` so that the staging switch serves the same upstream.

0 commit comments

Comments
 (0)