Version 1.1 introduced this code to read a base url:

+  // Find root url of server
+  if (isset($_SERVER['SERVER_NAME'])) {
+    $domain = $_SERVER['SERVER_NAME'];
+    if ($_SERVER['SERVER_PORT'] != 80) {
+      $domain .= ':' . $_SERVER['SERVER_PORT'];
+    }
+  }
+  elseif (isset($_SERVER['HTTP_HOST'])) {
+      $domain = $_SERVER['HTTP_HOST'];
+  }
+  $proto = $_SERVER['HTTPS'] ? 'https://' : 'http://';
+  $base_url = $proto . $domain;
+
+  $url = url($base_url . '/progress', array('query' => 'X-Progress-ID=' . $key, 'absolute' => TRUE, 'external' => TRUE));
+

but in my configurations with multiple domains using the same configuration file, the SERVER_NAME does not match the HTTP_HOST.

My server config is something like this:

server {
  listen 69.xx.xx.xx:80;
  listen 69.xx.xx.yy:80;

  server_name
    _drupal-boost
    www.example1.com
    www.example2.com
    www.example3.com
  ;

  root /var/www/$host/public;
  access_log /var/log/nginx/$host.access.log;
  ...

By default, nginx uses the first domain as the SERVER_NAME, so I put in a bogus name first so that requests to www.example3.com don't get SERVER_NAME=www.example1.com. Either way, it messes with the module unless there's only one domain defined.

Is there an advantage to use SERVER_NAME instead of HTTP_HOST?

Comments

smoothify’s picture

Hi Brian,

This code was added as a result of #876564: problem with drupal in sub dir, to fix issues of running drupal in a subdirectory.

It looks like I just overlooked this problem to get the subdir issue working, I'm not sure why I picked SERVER_NAME instead of HTTP_HOST really.

I will change this asap, am I right in thinking that I will still need to determine the SERVER_PORT for it to work in all cases using HTTP_HOST, or does the HTTP_HOST provide that information?

brianmercer’s picture

For me HTTP_HOST includes the port. I tested:

function nginx_progress_fetch($key) {
  $domain = $_SERVER['HTTP_HOST'];
  $proto = $_SERVER['HTTPS'] ? 'https://' : 'http://';
  $base_url = $proto . $domain;

  $url = url($base_url . '/progress', array('query' => 'X-Progress-ID=' . $key, 'absolute' => TRUE, 'external' => TRUE));

  $response = drupal_http_request($url);
  ...

on a random port and it worked fine. I'll test a subdirectory install later today and post the results.

Thanks much.

smoothify’s picture

Thanks for testing that for me Brian

I believe the subdirectory install should still work with that code, but i'll wait for your feedback before committing anything.

brianmercer’s picture

Title: multiple domains causes module to fail » name-based virtual host causes module to fail

I tested with a subdirectory install and odd port and it works great. Thanks.

smoothify’s picture

Tested and works for me too - Thanks.

Committed now, and new 1.2 release made.

smoothify’s picture

Status: Active » Fixed

changing status.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.