How Do I view my site via public IP address without pointing the domain?

March 27, 2019 326 views
Nginx Apache Node.js WordPress

I’m hosting a wordpress backend using Apache. I’m using Node to actually display the site (nextjs).

Additionally I’m using nginx reverse proxy for both Apache and Node.

so, I followed the guide and set up /etc/ngingx/sites-available/domain.com like this:

server {
        listen 80;
        listen [::]:80;

        root /var/www/domain.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name domain.com www.domain.com;

        location / {
        proxy_pass http://localhost:8090;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        }

        location /next {
        proxy_pass http://localhost:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        }

}

When I ssh in and run curl commands, I get the response from both ports.

Unforutnately I cannot yet point the domain to my IP. So in the meanwhile, how can I view the site in browser using public IP?

2 Answers

Greetings!

This is a great question. The standard way of doing this is to use your system host file. This is effectively overriding DNS locally on your system, allowing you to view the domain as though it’s DNS pointed somewhere other than where it actually does. I have a tutorial that I like for this here:

https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/

Jarland

@jarland thank you. I actually figured I should try that some time after posting this question. I am indeed able to view the site after doing this.

The problem that is confusing me though, is that I’m making API calls from inside my app to the domain.com/api-endpoint. So I don’t know what I should be doing with that, if anything. Right now my calls are not being returned.

  • Ah good thought! I think in this case you just do the same thing on the droplet. Edit /etc/hosts and add an entry just like the one you added on your home system, done :)

    • hmm I can try that. Though I have nginx reverse proxy in front, and behind that there’s Apache and Node.js. Node is my actual app… Is there a specific place I would do this, or it’s just globally on the droplet?

      • Your /etc/hosts file should override all DNS lookups unless your app isn’t relying on the system to to lookups, but that would be a bit unusual.

Have another answer? Share your knowledge.