Skip to content

Commit bcb26ab

Browse files
committed
Add all-in-one minimal nginx config
The nginx configuration uses a lot of defaults that work well in server-like environments. However, this is not optimized for a local dev-environment or single-container as codegate is meant to run. The nginx server spawns several processes which mostly remain idle. This is wasteful and it is taking over resources that could be used for something else. The intention of this new configuration is to minimize footprint. Signed-off-by: Juan Antonio Osorio <[email protected]>
1 parent 70fbc6e commit bcb26ab

File tree

2 files changed

+63
-17
lines changed

2 files changed

+63
-17
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ RUN chown -R codegate /var/lib/nginx && \
7878
chown -R codegate /var/log/nginx && \
7979
chown -R codegate /run
8080

81-
COPY nginx.conf /etc/nginx/conf.d/default.conf
81+
COPY nginx.conf /etc/nginx/nginx.conf
8282

8383
# Remove include /etc/nginx/sites-enabled/*; from the default nginx.conf
8484
# This way we don't introduce unnecessary configurations nor serve

nginx.conf

+62-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,68 @@
1-
server {
2-
listen 9090;
1+
worker_processes 1;
2+
pid /run/nginx.pid;
3+
error_log /var/log/nginx/error.log;
4+
include /etc/nginx/modules-enabled/*.conf;
35

4-
server_name localhost;
6+
events {
7+
worker_connections 128;
8+
}
9+
10+
http {
11+
12+
##
13+
# Basic Settings
14+
##
15+
16+
sendfile on;
17+
tcp_nopush on;
18+
types_hash_max_size 2048;
19+
20+
##
21+
# Disable unnecessary features
22+
##
23+
24+
server_tokens off;
25+
autoindex off;
26+
27+
include /etc/nginx/mime.types;
28+
default_type application/octet-stream;
29+
30+
##
31+
# Logging Settings
32+
##
33+
34+
access_log off;
35+
error_log /var/log/nginx/error.log;
36+
37+
##
38+
# Gzip Settings
39+
##
40+
41+
gzip on;
42+
43+
server {
44+
listen 9090;
45+
46+
server_name localhost;
547

6-
root /var/www/html;
7-
index index.html;
48+
add_header X-Frame-Options SAMEORIGIN;
49+
add_header X-Content-Type-Options nosniff;
50+
add_header X-XSS-Protection "1; mode=block";
851

9-
location / {
10-
try_files $uri /index.html =404;
11-
}
52+
root /var/www/html;
53+
index index.html;
1254

13-
# Serve certificates from /app/codegate_volume/certs at /certificates
14-
location /certificates/codegate_ca.crt {
15-
alias /app/codegate_volume/certs/ca.crt;
16-
types { application/x-x509-ca-cert crt; }
17-
default_type application/x-x509-ca-cert;
18-
}
55+
location / {
56+
try_files $uri /index.html =404;
57+
expires 1h; # Cache files for 1 hour
58+
add_header Cache-Control "public, max-age=3600";
59+
}
1960

20-
error_log /var/log/nginx/error.log;
21-
access_log /var/log/nginx/access.log;
61+
# Serve certificates from /app/codegate_volume/certs at /certificates
62+
location /certificates/codegate_ca.crt {
63+
alias /app/codegate_volume/certs/ca.crt;
64+
types { application/x-x509-ca-cert crt; }
65+
default_type application/x-x509-ca-cert;
66+
}
67+
}
2268
}

0 commit comments

Comments
 (0)