Skip to content

Commit

Permalink
Allow for nginx's server_names_hash_bucket_size option to be configured
Browse files Browse the repository at this point in the history
And clarify change in behavior in the tests. Now this option should only
need to be changed if a host is explicitly defined in the config that
exceeds the system's default limit. Hosts added via API Backends do not
require this setting to be changed (since we no longer define actual
server{} blocks for each hostname in the nginx config).
  • Loading branch information
GUI committed Jan 18, 2016
1 parent f01ebd2 commit 2e28aae
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
4 changes: 4 additions & 0 deletions templates/etc/nginx/router.conf.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ http {
gzip_types application/atom+xml application/javascript application/json application/rss+xml application/x-javascript application/xml text/css text/csv text/javascript text/plain text/xml;
gzip_vary on;

{{#nginx.server_names_hash_bucket_size}}
server_names_hash_bucket_size {{nginx.server_names_hash_bucket_size}};
{{/nginx.server_names_hash_bucket_size}}

upstream api_umbrella_web_app_backend {
server {{web.host}}:{{web.port}};
keepalive 10;
Expand Down
60 changes: 51 additions & 9 deletions test/integration/proxying.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ describe('proxying', function() {
},
},
{
frontend_host: 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
backend_host: 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
frontend_host: 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
backend_host: 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
servers: [
{
host: '127.0.0.1',
Expand Down Expand Up @@ -405,21 +405,17 @@ describe('proxying', function() {
});
}

// I'm not exactly sure why, but when we set server_names_hash_bucket_size
// to 128, it actually only allows hostnames 110 characters long. Perhaps
// something to investigate or better understand, but in the meantime
// documenting current behavior.
it('supports hostname lengths up to 110 characters', function(done) {
it('supports long hostnames without additional config when part of api backend hosts', function(done) {
var options = _.merge({}, this.options, {
headers: {
'Host': 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
'Host': 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
},
});

request.get('http://localhost:9080/long-host-info/', options, function(error, response, body) {
response.statusCode.should.eql(200);
var data = JSON.parse(body);
data.headers.host.length.should.eql(110);
data.headers.host.length.should.eql(200);
done();
});
});
Expand Down Expand Up @@ -1602,4 +1598,50 @@ describe('proxying', function() {
});
});
});

describe('long hostnames defined in "hosts" config require "nginx.server_names_hash_bucket_size" option to be adjusted', function() {
shared.runServer({
apis: [
{
frontend_host: 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
backend_host: 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
servers: [
{
host: '127.0.0.1',
port: 9444,
},
],
url_matches: [
{
frontend_prefix: '/long-host-in-hosts-info/',
backend_prefix: '/info/',
},
],
},
],
hosts: [
{
hostname: 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
},
],
nginx: {
server_names_hash_bucket_size: 200,
},
});

it('supports long hostnames', function(done) {
var options = _.merge({}, this.options, {
headers: {
'Host': 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
},
});

request.get('http://localhost:9080/long-host-in-hosts-info/', options, function(error, response, body) {
response.statusCode.should.eql(200);
var data = JSON.parse(body);
data.headers.host.length.should.eql(200);
done();
});
});
});
});

0 comments on commit 2e28aae

Please sign in to comment.