How to configure nginx for unqualified host names?

I am setting up nginx as a reverse proxy. I have only used Apache before, and without virtual hosts.

I want my users to be able to access various intranet web services by simply typing the name of the service into the address bar. E.g. to type "timesheets" rather than "timesheets.intranet.local".

On a client machine if I use "wget" or a browser to access the FQDN for the site (timesheets.intranet.local) then everything is fine.

On a client machine if I use "wget" or a browser to access the plain hostname for the site (timesheets) then it fails.

If I use "wget" locally on the nginx server machine then both work fine.

My site config looks like:

server {
  server_name timesheets timesheets.intranet.local;

  location / {
    proxy_pass http://127.0.0.1:8080;
  }

  listen [::]:443 ssl ipv6only=on;
  listen 443 ssl;
  ssl_certificate /root/timesheet.crt;
  ssl_certificate_key /root/timesheet.key;
}

Name resolution is not the problem. "wget" on the client machine correctly resolves the IP address but still fails to retrieve the page.


When configuring reverse proxying you must pay attention not only to a proxy configuration, but also consider a configuration of a service behind it.

Not only the proxy must accept a name in its virtualhost, but it must also issue a Host header which is expected to the backend. In this case easiest way is to configure both proxy and a backend to accept a short unqualified host name.

Alternate way might be to override which Host header proxy is sending to a backend. Then you only need your backend to server only that hostname. See this answer https://stackoverflow.com/questions/14352690/change-host-header-in-nginx-reverse-proxy