Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(conf): Support nginx user conf #2180

Merged
merged 1 commit into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many ) at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops..my fat finger..let me fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #2298

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