Reputation: 73
I'm hosting a API server using Docker Nginx server with Lumen, let say example.com, but now I want to change it to api.example.com. I tried editing my nginx.conf by adding server_name: api.example.com but it didn't work, but I still able to access example.com.
server {
listen 80;
server_name api.example.com;
root /app/public;
index index.php index.htm index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /index.php {
include fastcgi_params;
fastcgi_connect_timeout 10s;
fastcgi_read_timeout 10s;
fastcgi_buffers 256 4k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php:9000;
}
}
And then I found a tutorial on namecheap.com (where I bought my domain from) that I can create a subdomain via CNAME record.
Now I'm confused how subdomain is created? from the server configuration or from the domain regitrar?
Thanks
Upvotes: 3
Views: 64
Reputation: 23892
You need to set up both a domain name registration and a server configuration. The cname will send the request chris.example.com
to your servers actual location on the internet 192.168.1.1
(or what ever its IP is). Then you need to set chris.example.com
in the server's configuration folder so it loads the chris.example.com
codebase, and not the example.com
one.
When you type in domain.com
it goes to a DNS server and maps that to an IP address. The request then goes to that IP and the server decides what to load based on the domain name given. (The TTL is how long the IP address should be stay mapped to the domain name for locally (so you don't have to do multiple DN queries for domains you already know)).
Upvotes: 1