0

I am building a server on Ubuntu using Nginx + Gunicorn + Django.

I have a domain name registered with godaddy that redirects to the IP of the server. The Nginx configuration looks like this:

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name mydomainname.com www.mydomainname.com localhost;

        location / {
            proxy_redirect off;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass http://unix:/path/to/my/socket.sock;
        }
    }

When I type the domain name in the browser, I get correctly redirected to the server. However, the url in the browser now displays the IP instead of the domain name.

How can I make the server display the domain name instead of the IP?

(Godaddy provides an option to do this by using forward masking, but I have been advised not to use this, and the browser complains about cross-origin problems anyway when I try this approach.)

I'm not even sure if I need to change something in Nginx or Gunicorn or Django.

Florian Dietz
  • 101
  • 1
  • 4

2 Answers2

0

The sample configuration suggests that you also need to pass the Host: header upstream. For example, ripped out of that same configuration:

      proxy_set_header Host $http_host;
      # we don't want nginx trying to do something clever with
      # redirects, we set the Host: header above already.
      proxy_redirect off;
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
0

I found the problem, and it had nothing to do with Nginx's configuration. I was looking in the entirely wrong place.

I mistakenly set up a URL forwarding command at the website where I bought my domain name. I should have set up a type 'A' DNS record instead. I didn't know those were two different things and was unlucky enough to find the URL forwarding feature before finding the DNS records.

Florian Dietz
  • 101
  • 1
  • 4