Skip to content

Commit bd9e7e3

Browse files
committed
fix: custom nginx config for v1beta
1 parent 4d8a717 commit bd9e7e3

3 files changed

Lines changed: 160 additions & 3 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
# TODO: when removing v1beta, delete the file
12
version: '2.4'
23
services:
34
graphiql:
45
image: pokeapi/graphiql:2.0.0
6+
web:
7+
volumes:
8+
- ./Resources/nginx/nginx-gql-v1beta.conf:/etc/nginx/nginx.conf:ro
9+
- ./Resources/nginx/ssl:/ssl:ro
10+
- graphql_cache:/tmp/cache
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
worker_processes 1;
2+
3+
events {
4+
worker_connections 1024;
5+
multi_accept on;
6+
accept_mutex off;
7+
use epoll;
8+
}
9+
10+
http {
11+
access_log off;
12+
log_format pokeapilogformat
13+
'$remote_addr '
14+
'"$request" $status cs:$upstream_cache_status s:$bytes_sent '
15+
'r:"$http_referer"';
16+
error_log /dev/stdout warn;
17+
include mime.types;
18+
default_type application/octet-stream;
19+
20+
server_tokens off;
21+
22+
add_header X-XSS-Protection "1; mode=block";
23+
24+
client_body_buffer_size 10K;
25+
client_header_buffer_size 1k;
26+
client_max_body_size 8m;
27+
28+
sendfile on;
29+
tcp_nopush on;
30+
tcp_nodelay on;
31+
32+
keepalive_timeout 5;
33+
34+
gzip on;
35+
gzip_disable "msi6";
36+
gzip_vary on;
37+
gzip_proxied any;
38+
gzip_comp_level 4;
39+
gzip_buffers 16 8k;
40+
gzip_http_version 1.1;
41+
gzip_min_length 256;
42+
gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml;
43+
44+
resolver 127.0.0.11 valid=10s;
45+
46+
geo $limit {
47+
default 1;
48+
10.0.0.0/8 0;
49+
192.168.0.0/24 0;
50+
}
51+
52+
map $http_user_agent $exclude_ua {
53+
"~*monitoring*" 0;
54+
default 1;
55+
}
56+
57+
map $request_method $only_post {
58+
default 0;
59+
POST $exclude_ua;
60+
}
61+
62+
map $limit $limit_key {
63+
0 "";
64+
1 $binary_remote_addr;
65+
}
66+
67+
limit_req_zone $limit_key zone=graphqlDefaultLimit:50m rate=1r/m;
68+
limit_conn_zone $binary_remote_addr zone=addr:20m;
69+
proxy_cache_path /tmp/cache levels=1:2 keys_zone=small:40m inactive=10d max_size=2g use_temp_path=off;
70+
71+
upstream gqle {
72+
zone upstream_dynamic 64k;
73+
server graphql-engine:8080 resolve;
74+
}
75+
76+
server {
77+
listen 80 deferred;
78+
server_name _;
79+
root /code;
80+
81+
include /ssl/ssl.conf*;
82+
83+
client_body_timeout 5s;
84+
client_header_timeout 5s;
85+
limit_conn addr 10;
86+
87+
# Admin console
88+
location /graphql/admin/ {
89+
expires 1m;
90+
add_header Cache-Control "public";
91+
add_header Pragma public;
92+
proxy_http_version 1.1;
93+
proxy_set_header Upgrade $http_upgrade;
94+
proxy_set_header Connection "upgrade";
95+
proxy_set_header X-Real-IP $remote_addr;
96+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
97+
proxy_set_header Host $http_host;
98+
proxy_redirect off;
99+
set $upstream_graphql graphql-engine;
100+
proxy_pass http://gqle/;
101+
}
102+
103+
location /graphql/console {
104+
proxy_http_version 1.1;
105+
proxy_set_header Upgrade $http_upgrade;
106+
proxy_set_header Connection "upgrade";
107+
proxy_set_header X-Real-IP $remote_addr;
108+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
109+
proxy_set_header Host $http_host;
110+
set $upstream_graphiql graphiql;
111+
proxy_pass http://$upstream_graphiql:80/;
112+
}
113+
114+
location /graphql/v1beta {
115+
access_log /dev/stdout pokeapilogformat if=$only_post;
116+
include /ssl/cache.conf*;
117+
limit_req zone=graphqlDefaultLimit burst=200 nodelay;
118+
limit_req_status 429;
119+
expires 30m;
120+
add_header Cache-Control "public";
121+
add_header Pragma public;
122+
proxy_hide_header Access-Control-Allow-Origin;
123+
add_header Access-Control-Allow-Origin *;
124+
proxy_http_version 1.1;
125+
proxy_set_header Upgrade $http_upgrade;
126+
proxy_set_header Connection "upgrade";
127+
proxy_set_header X-Real-IP $remote_addr;
128+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
129+
proxy_set_header Host $http_host;
130+
proxy_redirect off;
131+
set $upstream_graphql graphql-engine;
132+
proxy_pass http://$upstream_graphql:8080/v1/graphql;
133+
}
134+
135+
location /api/ {
136+
expires 1m;
137+
add_header Cache-Control "public";
138+
add_header Pragma public;
139+
proxy_set_header X-Real-IP $remote_addr;
140+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
141+
proxy_set_header Host $http_host;
142+
proxy_redirect off;
143+
set $upstream app;
144+
proxy_pass http://$upstream:80;
145+
}
146+
147+
location / {
148+
return 404;
149+
}
150+
}
151+
}

Resources/nginx/nginx.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ http {
8585
limit_conn addr 10;
8686

8787
# Admin console
88-
location /graphql/admin/ {
88+
location /v1beta2/admin/ {
8989
expires 1m;
9090
add_header Cache-Control "public";
9191
add_header Pragma public;
@@ -100,7 +100,7 @@ http {
100100
proxy_pass http://gqle/;
101101
}
102102

103-
location /graphql/console {
103+
location /v1beta2/console {
104104
proxy_http_version 1.1;
105105
proxy_set_header Upgrade $http_upgrade;
106106
proxy_set_header Connection "upgrade";
@@ -111,7 +111,7 @@ http {
111111
proxy_pass http://$upstream_graphiql:80/;
112112
}
113113

114-
location /graphql/v1beta {
114+
location /v1beta2 {
115115
access_log /dev/stdout pokeapilogformat if=$only_post;
116116
include /ssl/cache.conf*;
117117
limit_req zone=graphqlDefaultLimit burst=200 nodelay;

0 commit comments

Comments
 (0)