nginx - 子域是通过域名注册商还是网络服务器创建的?

标签 nginx docker dns subdomain lumen

我正在使用带有 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 记录创建一个子域。

https://www.namecheap.com/support/knowledgebase/article.aspx/319/78/how-can-i-setup-an-a-address-record-for-my-domain

现在我很困惑子域是如何创建的?从服务器配置还是从域名注册商?

谢谢

最佳答案

您需要设置域名注册和服务器配置。 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/

相关文章:

dns - DNS 查找的人类可读形式

ruby-on-rails - 504 网关超时 nginx/1.4.6 (Ubuntu)

azure - 查找正确的 Azure Web 角色 IP 地址

ssl - NGINX 不会监听 443 端口

c# - 无法在 docker 容器内访问带有 dotnet/angular spa 应用程序的 API,但可以在 docker 容器外访问

java - 从Spring App(docker-compose)在Mongodb连接上获取 “Exception opening socket”

docker - 带有 docker 和 .NET Core 2.0 的 VSTS CI/CD - 复制失败

linux - AWS s3 文件通过 Laravel 上传失败

authentication - nginx auth_request : access original query parameter

nginx - 使用 nginx 和 uWSGI 的多个服务器进程