vhost.tpl.php 2.87 KB
Newer Older
1
<?php
2
if ($ssl_redirection || $this->redirection) {
3 4
  // 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
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
28 29 30 31 32 33
  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); ?>;
  fastcgi_param db_port   <?php print urlencode($db_port); ?>;
34 35
  listen        *:<?php print $http_port; ?>;
  server_name   <?php
36 37 38 39
    // 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) {
40
      print str_replace('/', '.', $this->redirection);
41 42 43
    } else {
      print $this->uri;
    }
44 45 46
    if (!$this->redirection && is_array($this->aliases)) {
      foreach ($this->aliases as $alias_url) {
        if (trim($alias_url)) {
47
          print " " . str_replace('/', '.', $alias_url);
48 49 50
        }
      }
    } ?>;
51
  root          <?php print "{$this->root}"; ?>;
52
  <?php print $extra_config; ?>
53 54 55 56
<?php
if ($this->redirection || $ssl_redirection) {
  if ($ssl_redirection && !$this->redirection) {
    // redirect aliases in non-ssl to the same alias on ssl.
57
    print "\n  rewrite ^ https://\$host\$request_uri? permanent;\n";
58 59 60
  }
  elseif ($ssl_redirection && $this->redirection) {
    // redirect all aliases + main uri to the main https uri.
61
    print "\n  rewrite ^ https://{$this->uri}\$request_uri? permanent;\n";
62 63
  }
  elseif (!$ssl_redirection && $this->redirection) {
64
    print "  include       " . $server->include_path . "/nginx_vhost_common.conf;\n";
65
  }
66
}
67
else {
68
  print "  include       " . $server->include_path . "/nginx_vhost_common.conf;\n";
69
}
70
$if_subsite = $this->data['http_subdird_path'] . '/' . $this->uri;
71
if (provision_hosting_feature_enabled('subdirs') && provision_file()->exists($if_subsite)->status()) {
72 73
  print "  include       " . $if_subsite . "/*.conf;\n";
}
74
?>
75
}