Ubuntu Nginx subomdain始终重定向到特定文件夹

Ubuntu Nginx subomdain始终重定向到特定文件夹,ubuntu,nginx,dns,Ubuntu,Nginx,Dns,我有一个叫shopify的网站https://mydomain-com. 此网站有3个子域,它们指向另一个服务器ip(A记录)。在我的服务器上,我有一个主根文件夹。如何确保所有3个子域都指向该根文件夹 因为现在它正在寻找子域文件夹。我无法将我的根域ip指向服务器,因为它是shopify网站 如何确保子域指向我的nginx服务器上的1个文件夹?您需要为每个子域创建配置。并为这些子域指定根目录。例如: server { listen 80; server_name subdomain1.

我有一个叫shopify的网站https://mydomain-com.

此网站有3个子域,它们指向另一个服务器ip(A记录)。在我的服务器上,我有一个主根文件夹。如何确保所有3个子域都指向该根文件夹

因为现在它正在寻找子域文件夹。我无法将我的根域ip指向服务器,因为它是shopify网站


如何确保子域指向我的nginx服务器上的1个文件夹?

您需要为每个子域创建配置。并为这些子域指定根目录。例如:

server {
   listen 80;
   server_name subdomain1.domain.com;

   root /path/to/directory;
   index index.html;
}

server {
   listen 80;
   server_name subdomain2.domain.com;

   root /path/to/directory;
   index index.html;
}

您可以在服务器的NGINX配置文件中执行此操作

server {
  listen 80;
  server_name _;

  root /path/to/directory;

  location / {
    try_files $uri $uri/ /index.html;
  }
}
但是,如果希望不同的子域指向不同的文件夹,可以将
server\u name
值更改为子域名称,如下所示:

server {
  listen 80;
  server_name subdomain1.domain.com;

  root /path/to/directory1;

  location / {
    try_files $uri $uri/ /index.html;
  }
}


server {
  listen 80;
  server_name subdomain2.domain.com;

  root /path/to/directory2;

  location / {
    try_files $uri $uri/ /index.html;
  }
}


server {
  listen 80;
  server_name subdomain3.domain.com;

  root /path/to/directory3;

  location / {
    try_files $uri $uri/ /index.html;
  }
}