How do I specify multiple domains in server_name for nginx configuration?

My question is similar to But I want to make sure that I have the correct information. Here’s my scenario:

I’m running a Bitnami Mattermost virtual machine. If I access it via my LAN, it redirects to the IP Address ( regardless of whether I put that in or its hostname (ac0ec-mattermost.local.mesh). To further complicate things, I want to access it from outside my network with (not really, but you get the drift). But when I go to my domain, it tries to redirect me to and fails.

Currently my configuration file has this:

server {
    listen  80 default_server;
    return  302 https://$server_name:443$return_uri;

Do I simply change that to

server {
    listen  80 default_server;
    server_name ac0ec-mattermost.local.mesh;
    return  302 https://$server_name:443$return_uri;

or would it be something like

server {
    listen  80 default_server;
    server_name ac0ec-mattermost;
    return  302 https://$server_name:443$return_uri;


If it’s something completely different, I would appreciate the correct configuration (including if I have to create additional entries under the https section).

Thanks, and have a great evening. :) Patrick.

Edited to add this:

Here is the relevant portion of my mattermost.conf file (which Nginx loads) with the changes that I think would work.

upstream backend {

server {
   listen         80 default_server;
    server_name ac0ec-mattermost.local.mesh;
   return         302 https://$server_name:443$request_uri;

proxy_cache_path /opt/bitnami/nginx/cache levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_$
server {
   listen 443 ssl;
    server_name ac0ec-mattermost.local.mesh;

   ssl on;
   ssl_certificate /opt/bitnami/apps/mattermost/conf/certs/server.crt;
   ssl_certificate_key /opt/bitnami/apps/mattermost/conf/certs/server.key;
   ssl_session_timeout 5m;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_prefer_server_ciphers on;
   ssl_session_cache shared:SSL:10m;

   location /api/v4/websocket {
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header X-Forwarded-Ssl on;
      client_max_body_size 50M;
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Frame-Options SAMEORIGIN;
      proxy_buffers 256 16k;
      proxy_buffer_size 16k;
      proxy_read_timeout 600s;
      proxy_pass http://backend;

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there @pdickey52761,

The Nginx configuration that you have in there actually looks good in terms of the server_name definition.

Are you still seeing the redirect with that configuration?

Regards, Bobby