Skip to content

Commit d77a64a

Browse files
committed
Use default log format, set resolver and worker_processes dynamically
1 parent e2e39b9 commit d77a64a

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

root/defaults/nginx.conf

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
user abc;
44

55
# Set number of worker processes automatically based on number of CPU cores.
6-
worker_processes auto;
6+
include /config/nginx/worker_processes.conf
77

88
# Enables the use of JIT for regular expressions to speed-up their processing.
99
pcre_jit on;
1010

1111
# Configures default error logger.
12-
error_log /config/log/nginx/error.log warn;
12+
error_log /config/log/nginx/error.log;
1313

1414
# Includes files with directives to load dynamic modules.
1515
include /etc/nginx/modules/*.conf;
@@ -29,7 +29,8 @@ http {
2929

3030
# Name servers used to resolve names of upstream servers into addresses.
3131
# It's also needed when using tcpsocket and udpsocket in Lua modules.
32-
resolver 127.0.0.11 valid=30s; # Docker DNS Server
32+
#resolver 1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001;
33+
include /config/nginx/resolver.conf
3334

3435
# Don't tell nginx version to the clients. Default is 'on'.
3536
server_tokens off;
@@ -54,18 +55,11 @@ http {
5455
'' close;
5556
}
5657

57-
# Specifies the main log format.
58-
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
59-
'$status $body_bytes_sent "$http_referer" '
60-
'"$http_user_agent" "$http_x_forwarded_for"';
61-
6258
# Sets the path, format, and configuration for a buffered log write.
63-
access_log /config/log/nginx/access.log main;
59+
access_log /config/log/nginx/access.log;
6460

6561
# Includes virtual hosts configs.
66-
include /etc/nginx/http.d/*.conf;
67-
include /config/nginx/site-confs/*;
68-
#Removed lua. Do not remove this comment
62+
#include /etc/nginx/http.d/*.conf;
6963

7064
# WARNING: Don't use this directory for virtual hosts anymore.
7165
# This include will be moved to the root context in Alpine 3.14.
@@ -116,6 +110,12 @@ http {
116110
#passenger_root /usr;
117111
#passenger_ruby /usr/bin/ruby;
118112

113+
##
114+
# Virtual Host Configs
115+
##
116+
include /config/nginx/site-confs/*;
117+
#Removed lua. Do not remove this comment
118+
119119
##
120120
# Geoip2 config
121121
##
@@ -125,9 +125,6 @@ http {
125125
#include /config/nginx/geoip2.conf;
126126
}
127127

128-
# TIP: Uncomment if you use stream module.
129-
#include /etc/nginx/stream.conf;
130-
131128
#mail {
132129
# # See sample authentication script at:
133130
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
@@ -148,5 +145,6 @@ http {
148145
# proxy on;
149146
# }
150147
#}
148+
151149
daemon off;
152150
pid /run/nginx.pid;

root/etc/cont-init.d/50-config

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,22 @@ cp /config/fail2ban/jail.local /etc/fail2ban/jail.local
8181
[[ ! -f /config/www/502.html ]] &&
8282
cp /defaults/502.html /config/www/502.html
8383

84+
# Set resolver
85+
if ! grep -q 'resolver' /config/nginx/resolver.conf; then
86+
RESOLVER=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
87+
echo "Setting resolver to ${RESOLVER}"
88+
echo "resolver ${RESOLVER} valid=30s;" > /config/nginx/resolver.conf
89+
fi
90+
91+
# Set worker_processes
92+
if ! grep -q 'worker_processes' /config/nginx/worker_processes.conf; then
93+
WORKER_PROCESSES=$(wc -w < /sys/fs/cgroup/cpuacct/cpuacct.usage_percpu)
94+
echo "Setting worker_processes to ${WORKER_PROCESSES}"
95+
echo "worker_processes ${WORKER_PROCESSES};" > /config/nginx/worker_processes.conf
96+
fi
97+
8498
# remove lua bits from nginx.conf if not done before
85-
if ! grep -q '#Removed lua' /config/nginx/nginx.conf; then
99+
if ! grep -q '#Removed lua' /config/nginx/nginx.conf; then
86100
echo "Removing lua specific info from nginx.conf"
87101
sed -i 's|\tlua_load_resty_core off;|\t#Removed lua. Do not remove this comment|g' /config/nginx/nginx.conf
88102
fi

0 commit comments

Comments
 (0)