vhost.tpl.php 3 KB
Newer Older
1 2 3 4
<?php
if ($ssl_redirection || $this->redirection) {
  // Redirect all aliases to the main http url using separate vhosts blocks to avoid if{} in Nginx.
  foreach ($this->aliases as $alias_url) {
5
    print "# alias redirection virtual host\n";
6
    print "server {\n";
7
    print "  listen       *:{$http_port};\n";
8 9 10 11
    // if we use redirections, we need to change the redirection
    // target to be the original site URL ($this->uri instead of
    // $alias_url)
    if ($this->redirection && $alias_url == $this->redirection) {
12
      $this->uri = str_replace('/', '.', $this->uri);
13 14
      print "  server_name  {$this->uri};\n";
    } else {
15
      $alias_url = str_replace('/', '.', $alias_url);
16 17
      print "  server_name  {$alias_url};\n";
    }
18
    print "  access_log   off;\n";
19
    print "  rewrite ^ \$scheme://{$this->redirection}\$request_uri? permanent;\n";
20 21 22
    print "}\n";
  }
}
23
?>
24 25

server {
26
  include       fastcgi_params;
27 28
  fastcgi_param MAIN_SITE_NAME <?php print $this->uri; ?>;
  set $main_site_name "<?php print $this->uri; ?>";
29
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
30 31 32 33 34
  fastcgi_param db_type   <?php print urlencode($db_type); ?>;
  fastcgi_param db_name   <?php print urlencode($db_name); ?>;
  fastcgi_param db_user   <?php print urlencode($db_user); ?>;
  fastcgi_param db_passwd <?php print urlencode($db_passwd); ?>;
  fastcgi_param db_host   <?php print urlencode($db_host); ?>;
35
  fastcgi_param db_port   <?php print urlencode($this->server->db_port); ?>;
36 37
  listen        *:<?php print $http_port; ?>;
  server_name   <?php
38 39 40 41
    // this is the main vhost, so we need to put the redirection
    // target as the hostname (if it exists) and not the original URL
    // ($this->uri)
    if ($this->redirection) {
42
      print str_replace('/', '.', $this->redirection);
43 44 45
    } else {
      print $this->uri;
    }
46 47 48
    if (!$this->redirection && is_array($this->aliases)) {
      foreach ($this->aliases as $alias_url) {
        if (trim($alias_url)) {
49
          print " " . str_replace('/', '.', $alias_url);
50 51 52
        }
      }
    } ?>;
53
  root          <?php print "{$this->root}"; ?>;
54
  <?php print $extra_config; ?>
55 56 57 58
<?php
if ($this->redirection || $ssl_redirection) {
  if ($ssl_redirection && !$this->redirection) {
    // redirect aliases in non-ssl to the same alias on ssl.
59
    print "\n  rewrite ^ https://\$host\$request_uri? permanent;\n";
60 61 62
  }
  elseif ($ssl_redirection && $this->redirection) {
    // redirect all aliases + main uri to the main https uri.
63
    print "\n  rewrite ^ https://{$this->redirection}\$request_uri? permanent;\n";
64 65
  }
  elseif (!$ssl_redirection && $this->redirection) {
66
    print "  include       " . $server->include_path . "/nginx_vhost_common.conf;\n";
67
  }
68
}
69
else {
70
  print "  include       " . $server->include_path . "/nginx_vhost_common.conf;\n";
71
}
72
$if_subsite = $this->data['http_subdird_path'] . '/' . $this->uri;
73
if (provision_hosting_feature_enabled('subdirs') && provision_file()->exists($if_subsite)->status()) {
74 75
  print "  include       " . $if_subsite . "/*.conf;\n";
}
76
?>
77
}