diff --git a/root/defaults/nginx.conf b/root/defaults/nginx.conf index 9497c0b..b56a5c7 100644 --- a/root/defaults/nginx.conf +++ b/root/defaults/nginx.conf @@ -3,13 +3,13 @@ user abc; # Set number of worker processes automatically based on number of CPU cores. -worker_processes auto; +include /config/nginx/worker_processes.conf # Enables the use of JIT for regular expressions to speed-up their processing. pcre_jit on; # Configures default error logger. -error_log /config/log/nginx/error.log warn; +error_log /config/log/nginx/error.log; # Includes files with directives to load dynamic modules. include /etc/nginx/modules/*.conf; @@ -29,7 +29,8 @@ http { # Name servers used to resolve names of upstream servers into addresses. # It's also needed when using tcpsocket and udpsocket in Lua modules. - resolver 127.0.0.11 valid=30s; # Docker DNS Server + #resolver 1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001; + include /config/nginx/resolver.conf # Don't tell nginx version to the clients. Default is 'on'. server_tokens off; @@ -54,18 +55,11 @@ http { '' close; } - # Specifies the main log format. - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - # Sets the path, format, and configuration for a buffered log write. - access_log /config/log/nginx/access.log main; + access_log /config/log/nginx/access.log; # Includes virtual hosts configs. - include /etc/nginx/http.d/*.conf; - include /config/nginx/site-confs/*; - #Removed lua. Do not remove this comment + #include /etc/nginx/http.d/*.conf; # WARNING: Don't use this directory for virtual hosts anymore. # This include will be moved to the root context in Alpine 3.14. @@ -116,6 +110,12 @@ http { #passenger_root /usr; #passenger_ruby /usr/bin/ruby; + ## + # Virtual Host Configs + ## + include /config/nginx/site-confs/*; + #Removed lua. Do not remove this comment + ## # Geoip2 config ## @@ -125,9 +125,6 @@ http { #include /config/nginx/geoip2.conf; } -# TIP: Uncomment if you use stream module. -#include /etc/nginx/stream.conf; - #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript @@ -148,5 +145,6 @@ http { # proxy on; # } #} + daemon off; pid /run/nginx.pid; diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index ceb22f4..eb842cb 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -81,8 +81,22 @@ cp /config/fail2ban/jail.local /etc/fail2ban/jail.local [[ ! -f /config/www/502.html ]] && cp /defaults/502.html /config/www/502.html +# Set resolver +if ! grep -q 'resolver' /config/nginx/resolver.conf; then + RESOLVER=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf) + echo "Setting resolver to ${RESOLVER}" + echo "resolver ${RESOLVER} valid=30s;" > /config/nginx/resolver.conf +fi + +# Set worker_processes +if ! grep -q 'worker_processes' /config/nginx/worker_processes.conf; then + WORKER_PROCESSES=$(wc -w < /sys/fs/cgroup/cpuacct/cpuacct.usage_percpu) + echo "Setting worker_processes to ${WORKER_PROCESSES}" + echo "worker_processes ${WORKER_PROCESSES};" > /config/nginx/worker_processes.conf +fi + # remove lua bits from nginx.conf if not done before -if ! grep -q '#Removed lua' /config/nginx/nginx.conf; then +if ! grep -q '#Removed lua' /config/nginx/nginx.conf; then echo "Removing lua specific info from nginx.conf" sed -i 's|\tlua_load_resty_core off;|\t#Removed lua. Do not remove this comment|g' /config/nginx/nginx.conf fi