• Welcome to Web Hosting Community Forum for Webmasters - Web hosting Forum.
 

Connect VPS with domain

Started by cloudytechi147, December 16, 2021, 03:58:20 PM

WordPress Premium Themes


cloudytechi147

I have a website with the frontend and backend hosted with different hosting providers. The fronted of the app is in Vercel while the backend is in Linode. I also bought a domain in Cheapname, namely example.com. Right now both www.example.com and example.com redirect to the Vercel frontend app. The backend is hosted on a VPS and I'm using Nginx for the server. The backend can be accessed using the IP of the cheapest vps hosting.

What I want: Access the frontend app with example.com and www.example.com (so far this part works), and access the backend when using the subdomain api.example.com (this does not).

What I have done so far: Changed the DNS for Cheapname and Vercel:


A Record    @ 76.76.21.21
CNAME Record    www cname.vercel-dns.com.
CAA Record  0 issue "letsencrypt.org"


Because I want the backend to only be accessed through api.example.com I set the configuration of nginx as follows:

server {
    listen 80;
    server_name api.exaple.com;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/myuser/myproject;
    }
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/myuser/myproject/myproject.sock;
    }
    client_max_body_size 100M;
}


Then, I put this on Namecheap:

A Record    api    xxx.xx.xx.xx
CNAME Record    api  xxx-xx-xx-xx.ip.linodeusercontent.com.


where xxx.xx.xx.xx is the ip address of the vps

The Problem: When I try to access api.example.com it redirects me to https:\\api.example.com and it gives me a 404 error (Vercel 404!!!). I'm a newbie with DNS, I would appreciate any help!!! Thank you in advance! =)

Kailash

If your subdomain is redirecting to wrong URL, it is most likely related to your nginx configuration or .htaccess rule issue. You should review your .htaccess rule and nginx configuration. Also, it is recommended to activate free Let's Encrypt SSL so that you can use HTTPs for your subdomain.

- Kailash

myresellerhome

Before you can use your domain with your VPS hosting, you must first link the domain and server by directing the domain to it. There's no need to worry since it's really simple, and there are plenty of possibilities.
NOTES: Changes should be made from the service where your domain is referred by Nameservers.
Managing DNS records at several registrars
Option 1 - A record
The simplest method for linking your domain to a VPS is to use A records; the protocol is as follows:
1. Get your VPS IP
2. Navigate to your domain DNS Zone and delete any A records that include @, www or cloudflare-resolve-to in its name
3. Add these two new A records
Option 2 - A and CNAME records
1. Get your VPS IP
2. Navigate to your domain DNS Zone and delete any A records that include @, www or cloudflare-resolve-to in its name
3. Add this A record along with this CNAME record
My Reseller Home |Reseller Hosting | VPS | Shared Hosting |

WordPress Premium Themes