Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

nginx: Allow configuring an explicit server_name.

bhuvan-somisettyd45e35125c6c
diff --git a/docs/production/install-existing-server.md b/docs/production/install-existing-server.md
index 4566f417280..c66a8d6d12f 100644
--- a/docs/production/install-existing-server.md
+++ b/docs/production/install-existing-server.md
@@ -52,9 +52,11 @@ Zulip's Puppet configuration will change the ownership of
`/var/log/nginx` so that the `zulip` user can access it. Depending on
your configuration, this may or may not cause problems.
-Depending on how you have configured `nginx` for your other services,
-you may need to add a `server_name` for the Zulip `server` block in
-the `nginx` configuration.
+Depending on how you have configured `nginx` for your other
+services, you may need to set
+[`nginx_server_name`](system-configuration.md#nginx_server_name) in
+`/etc/zulip/zulip.conf`, so that Zulip's `nginx` `server` blocks
+only claim requests for their intended hostnames.
### Puppet
diff --git a/docs/production/system-configuration.md b/docs/production/system-configuration.md
index 9e920725ab5..e64879e4f80 100644
--- a/docs/production/system-configuration.md
+++ b/docs/production/system-configuration.md
@@ -113,6 +113,28 @@ SSL/TLS termination.
Set to the port number if you [prefer to listen on a port other than
443](deployment.md#using-an-alternate-port).
+#### `nginx_server_name`
+
+Sets the [`server_name`][nginx_server_name] directive on Zulip's
+nginx `server` blocks; by default it is unset, so they match any
+hostname. Set it if you run other software alongside Zulip whose
+nginx configuration would otherwise claim requests meant for Zulip.
+List every hostname Zulip is served on, separated by spaces,
+including those on its TLS certificate; otherwise automatic
+certificate renewal will fail.
+
+If Zulip is served on more than one hostname, or on a hostname plus
+several subdomains, list them all; nginx's `server_name` supports a
+trailing wildcard for matching subdomains. For example, to serve
+Zulip on both `example.com` and any subdomain of it:
+
+```ini
+[application_server]
+nginx_server_name = example.com *.example.com
+```
+
+[nginx_server_name]: https://nginx.org/en/docs/http/server_names.html
+
#### `nginx_worker_processes`
Adjusts the [`worker_processes`][nginx_worker_processes] setting in
diff --git a/puppet/zulip/manifests/profile/app_frontend.pp b/puppet/zulip/manifests/profile/app_frontend.pp
index 8305f91b37b..cfef75f8364 100644
--- a/puppet/zulip/manifests/profile/app_frontend.pp
+++ b/puppet/zulip/manifests/profile/app_frontend.pp
@@ -10,6 +10,7 @@ class zulip::profile::app_frontend {
} else {
$nginx_listen_port = zulipconf('application_server', 'nginx_listen_port', 443)
}
+ $nginx_server_name = zulipconf('application_server', 'nginx_server_name', '')
$ssl_dir = $facts['os']['family'] ? {
'Debian' => '/etc/ssl',
'RedHat' => '/etc/pki/tls',
diff --git a/puppet/zulip/templates/nginx/zulip-enterprise.template.erb b/puppet/zulip/templates/nginx/zulip-enterprise.template.erb
index 662b10e3ac2..0d89714febb 100644
--- a/puppet/zulip/templates/nginx/zulip-enterprise.template.erb
+++ b/puppet/zulip/templates/nginx/zulip-enterprise.template.erb
@@ -15,6 +15,9 @@ server {
server {
listen 80;
listen [::]:80;
+<% if @nginx_server_name != '' -%>
+ server_name <%= @nginx_server_name %>;
+<% end -%>
location / {
return 301 https://$host$request_uri;
@@ -42,6 +45,9 @@ server {
ssl_certificate <%= @ssl_dir %>/certs/zulip.combined-chain.crt;
ssl_certificate_key <%= @ssl_dir %>/private/zulip.key;
<% end -%>
+<% if @nginx_server_name != '' -%>
+ server_name <%= @nginx_server_name %>;
+<% end -%>
include /etc/nginx/zulip-include/certbot;
include /etc/nginx/zulip-include/app;