Sir Rubberduck
Sir Rubberduck

Reputation: 2262

nginx showing IP address instead of domain

I have a godaddy A record pointing to my Digital Ocean IP address.

Here's the nginx configuration.

server {
    listen 80 default_server;
    server_name domain.com www.domain.com;
    location / {
       proxy_pass 'http://127.0.0.1:3004';
    }
}

When I type in the domain.com it goes to the server, but the address bar shows the IP address.

How can it show the domain name?

Upvotes: 5

Views: 6117

Answers (3)

Mohammed S.
Mohammed S.

Reputation: 49

This issue is coming from Godaddy's default forwarding configurations. You must talk to their support team to make the necessary changes. That is how I resolved the same issue with them.

Upvotes: 0

Maiko Bossuyt
Maiko Bossuyt

Reputation: 199

The redirection to the IP address is most likely done by your backend in the proxy_pass. You could try to add some header to help the backend understand the context of the request.

I would recommend as a starter the following configuration :

server {
    listen 80 default_server;
    server_name domain.com www.domain.com;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;


    location / {
       proxy_pass 'http://127.0.0.1:3004';
    }
}

If using Node.JS, you might need the following line as well :

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';

Please also check the configuration of your backend. You may need to setup the access URL, context path, etc.

Upvotes: 0

Ahmet
Ahmet

Reputation: 136

It's most probably a redirection from proxy_pass. I'm not sure what you are running at backend but you could try to pass hostname.

proxy_set_header Host      $host;

Add this line after proxy_pass to tell backend which domain is in the request headers.

Upvotes: 2

Related Questions