Skip to content

Commit 288373b

Browse files
committed
Add configuration for CrateDB HTTP API endpoint on a subdirectory path
1 parent 53438bf commit 288373b

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#############################
2+
CrateDB HTTP API behind Nginx
3+
#############################
4+
5+
6+
*****
7+
About
8+
*****
9+
10+
Nginx configuration for hosting the CrateDB HTTP API endpoint on a subdirectory
11+
path. Here: `/db`.
12+
13+
14+
*****
15+
Usage
16+
*****
17+
18+
Start CrateDB::
19+
20+
docker run -it --rm --publish=4200:4200 --publish=5432:5432 --name=cratedb crate/crate:5.0.1 -Cdiscovery.type=single-node -Ccluster.routing.allocation.disk.threshold_enabled=false
21+
22+
Start Nginx::
23+
24+
wget https://raw.githubusercontent.com/crate/cratedb-examples/main/spikes/http-api-behind-nginx/nginx.conf
25+
nginx -c $(pwd)/nginx.conf
26+
27+
Then, navigate to http://localhost:7070/db/.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Nginx configuration for hosting the CrateDB HTTP API endpoint on a subdirectory path.
2+
# Here: `/db`.
3+
4+
daemon off;
5+
error_log /dev/stderr info;
6+
7+
worker_processes 1;
8+
9+
events {
10+
worker_connections 256;
11+
}
12+
13+
http {
14+
keepalive_timeout 65;
15+
access_log /dev/stderr;
16+
17+
server {
18+
listen 7070;
19+
server_name localhost;
20+
21+
location /db/ {
22+
23+
# Cut away the `/db` prefix and reverse-proxy requests to CrateDB on `localhost`.
24+
rewrite ^/db/(.*)$ /$1 break;
25+
proxy_pass http://localhost:4200/;
26+
27+
# Obligatory configuration for setting appropriate HTTP headers.
28+
proxy_set_header Host $http_host;
29+
proxy_set_header X-Real-IP $remote_addr;
30+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31+
# proxy_set_header X-Forwarded-Proto https;
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)