Skip to content

Commit

Permalink
feat(conf): Support nginx user conf
Browse files Browse the repository at this point in the history
Support user config for nginx, especially when using Kong with docker
where the user may be someone weird.

Signed-off-by: Wei.ZHAO <zhaowei@qiyi.com>
  • Loading branch information
depay committed Mar 29, 2017
1 parent 06939d8 commit cfc15e3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
# HTTPS requests to the admin API, if
# `admin_ssl` is enabled.

#nginx_user = nobody # Defines user and group credentials used by
# worker processes. If group is omitted, a
# group whose name equals that of user is
# used. Ex: [user] [group].

#nginx_worker_processes = auto # Determines the number of worker processes
# spawned by Nginx.

Expand Down
1 change: 1 addition & 0 deletions kong/conf_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ local CONF_INFERENCES = {
cluster_listen = {typ = "string"},
cluster_listen_rpc = {typ = "string"},
cluster_advertise = {typ = "string"},
nginx_user = {typ = "string"},
nginx_worker_processes = {typ = "string"},
upstream_keepalive = {typ = "number"},

Expand Down
1 change: 1 addition & 0 deletions kong/templates/kong_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ proxy_listen = 0.0.0.0:8000
proxy_listen_ssl = 0.0.0.0:8443
admin_listen = 0.0.0.0:8001
admin_listen_ssl = 0.0.0.0:8444
nginx_user = nobody
nginx_worker_processes = auto
nginx_optimizations = on
nginx_daemon = on
Expand Down
1 change: 1 addition & 0 deletions kong/templates/nginx.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
return [[
user ${{NGINX_USER}};
worker_processes ${{NGINX_WORKER_PROCESSES}};
daemon ${{NGINX_DAEMON}};
Expand Down
3 changes: 3 additions & 0 deletions spec/01-unit/02-conf_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe("Configuration loader", function()
it("loads the defaults", function()
local conf = assert(conf_loader())
assert.is_string(conf.lua_package_path)
assert.equal("nobody", conf.nginx_user)
assert.equal("auto", conf.nginx_worker_processes)
assert.equal("0.0.0.0:8001", conf.admin_listen)
assert.equal("0.0.0.0:8000", conf.proxy_listen)
Expand All @@ -21,6 +22,7 @@ describe("Configuration loader", function()
-- defaults
assert.equal("on", conf.nginx_daemon)
-- overrides
assert.equal("nobody", conf.nginx_user)
assert.equal("1", conf.nginx_worker_processes)
assert.equal("0.0.0.0:9001", conf.admin_listen)
assert.equal("0.0.0.0:9000", conf.proxy_listen)
Expand All @@ -39,6 +41,7 @@ describe("Configuration loader", function()
-- defaults
assert.equal("on", conf.nginx_daemon)
-- overrides
assert.equal("nobody", conf.nginx_user)
assert.equal("auto", conf.nginx_worker_processes)
assert.equal("127.0.0.1:9001", conf.admin_listen)
assert.equal("0.0.0.0:9000", conf.proxy_listen)
Expand Down
1 change: 1 addition & 0 deletions spec/01-unit/03-prefix_handler_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe("NGINX conf compiler", function()
describe("compile_nginx_conf()", function()
it("compiles a main NGINX conf", function()
local nginx_conf = prefix_handler.compile_nginx_conf(helpers.test_conf)
assert.matches("user nobody;", nginx_conf, nil, true))
assert.matches("worker_processes 1;", nginx_conf, nil, true)
assert.matches("daemon on;", nginx_conf, nil, true)
end)
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/custom_nginx.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This is a custom nginx configuration template for Kong specs

user ${{NGINX_USER}};
worker_processes ${{NGINX_WORKER_PROCESSES}};
daemon ${{NGINX_DAEMON}};

Expand Down

0 comments on commit cfc15e3

Please sign in to comment.