我正在使用带有 Lumen 的 Docker Nginx 服务器托管一个 API 服务器,比方说 example.com,但现在我想将它更改为 api.example.com。我尝试通过添加 server_name: api.example.com 来编辑我的 nginx.conf,但它没有用,但我仍然能够访问 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;
}
}
然后我在 namecheap.com(我从那里购买了我的域)上找到了一个教程,我可以通过 CNAME 记录创建一个子域。
现在我很困惑子域是如何创建的?从服务器配置还是从域名注册商?
谢谢
最佳答案
您需要设置域名注册和服务器配置。 cname 将请求 chris.example.com
发送到您的服务器在互联网上的实际位置 192.168.1.1
(或者它的 IP 是什么)。然后您需要在服务器的配置文件夹中设置 chris.example.com
以便它加载 chris.example.com
代码库,而不是 example.com
一个。
当您输入 domain.com
时,它会转到 DNS 服务器并将其映射到 IP 地址。然后请求转到该 IP,服务器根据给定的域名决定加载什么。 (TTL 是 IP 地址应在本地保持映射到域名的时间长度(因此您不必对已知的域执行多个 DN 查询))。
关于nginx - 子域是通过域名注册商还是网络服务器创建的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39650510/