【问题标题】:Subdomain setup nginx子域设置 nginx
【发布时间】:2023-12-10 06:40:01
【问题描述】:

我的 reviewer24.com.conf 文件如下所示:

server {
  server_name reviewer24.com www.reviewer24.com;

  access_log /home/nginx/domains/reviewer24.com/log/access.log combined buffer=32k;
  error_log /home/nginx/domains/reviewer24.com/log/error.log;

  root /home/nginx/domains/reviewer24.com/public;

  location / {

  # Enables directory listings when index file not found
  #autoindex  on;

  # Shows file listing times as local time
  #autoindex_localtime on;

  # Enable for vBulletin usage WITHOUT vbSEO installed
  #try_files         / /index.php;

  }

  include /usr/local/nginx/conf/staticfiles.conf;
  include /usr/local/nginx/conf/php.conf;
  include /usr/local/nginx/conf/drop.conf;
  #include /usr/local/nginx/conf/errorpage.conf;
}

我创建了一个文件夹“m”并在其中放置了该网站的移动版本。 我应该在这个 .conf 文件中添加什么规则,这样当您转到:http://m.reviewer24.com 时,它将显示“m”文件夹中的内容?

【问题讨论】:

    标签: nginx subdomain virtualhost


    【解决方案1】:

    我会专门为您的移动网站创建一个新的 .conf 文件,例如在 m.reviewer24.com.conf 中使用新的服务器块然后重新加载您的 nginx 配置。

    这样,如果您需要对子域配置进行特定更改,则更易于管理。或者,您可以将新服务器块附加到现有配置中。

    您可能还想指定移动流量访问和错误日​​志的位置:)

    server {
      server_name m.reviewer24.com;
    
      access_log /home/nginx/domains/reviewer24.com/log/access.log combined buffer=32k;
      error_log /home/nginx/domains/reviewer24.com/log/error.log;
    
      root /home/nginx/domains/reviewer24.com/public/m;
    
      location / {
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      # Enable for vBulletin usage WITHOUT vbSEO installed
      #try_files         / /index.php;
    
      }
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
    }
    

    【讨论】: