I have drupal running on http://localhost:8080/drupal and this is how domain access is configured
Primary domain name: localhost
Sub-domain: sub.localhost

With this configuration everytime I access http://sub.localhost:8080/drupal, it always fall back to primary domain.
The reason is domain access could not identify it as a valid domain. The problem is in this line

// Cribbed from bootstrap.inc -- removes port protocols from the host value.
$_subdomain = strtolower(implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));

That line doesn't remove port protocol from the host value, it simply take this value sub.localhost:8080 and
transform it to 8080.sub.localhost. Then when DA trying to look for a domain record with that value, surely it
would never find it.

Suggested patch attached.

Comments

ariflukito’s picture

StatusFileSize
new1.44 KB

domain_get_uri() still needs to be fixed to include port number

edit: new patch

agentrickard’s picture

Status: Active » Needs work

That line, by the way, is cribbed from Drupal's bootstrap.inc -- settings files can recognize different ports as desired.

Thanks for the patch, a little testing is required to make sure it doesn't break anything -- it shouldn't. You could, of course, register your domains as 8080.example.com.

Similar logic is in the settings includes for Domain Prefix and Domain Conf, so the patch would need to be extended to them.

ariflukito’s picture

StatusFileSize
new3.72 KB

I don't see how registering domains as 8080.example.com would work. The path to the domain will be http://8080.example.com and the webserver is not running on port 80.

edit: new patch testing needed

agentrickard’s picture

Status: Needs work » Needs review

I am also not sure why we need to support non-standard ports.

ariflukito’s picture

Well for me the reason is to support different environments. My development server is running on port 8080 and port 80 is already used by IIS. I think it is useful for testing.

agentrickard’s picture

This has come up before -- the issue is for people who allow both port 80 and 8080 on the server. How do we handle those?

agentrickard’s picture

Status: Needs review » Needs work

Patch is malformed. Please use UNIX formatted linebreaks and patch against HEAD.

http://drupal.org/patch/create

agentrickard’s picture

StatusFileSize
new3.84 KB

There was also an issue with Windows line breaks in the settings_domain_prefix.inc file.

This patch is actually against DRUPAL-5 not HEAD (HEAD is D6),

Seems to be working.

agentrickard’s picture

Status: Needs work » Needs review
agentrickard’s picture

Status: Needs review » Needs work

Here's the issue that I have -- and it needs research and feedback. The RFC for HTTP says that ports are part of the URL, and that port 80 is the default:

http://www.ietf.org/rfc/rfc2616.txt

3.2.3 URI Comparison

   When comparing two URIs to decide if they match or not, a client
   SHOULD use a case-sensitive octet-by-octet comparison of the entire
   URIs, with these exceptions:

      - A port that is empty or not given is equivalent to the default
        port for that URI-reference;

        - Comparisons of host names MUST be case-insensitive;

        - Comparisons of scheme names MUST be case-insensitive;

        - An empty abs_path is equivalent to an abs_path of "/".

   Characters other than those in the "reserved" and "unsafe" sets (see
   RFC 2396 [42]) are equivalent to their ""%" HEX HEX" encoding.

   For example, the following three URIs are equivalent:

      http://abc.com:80/~smith/home.html
      http://ABC.com/%7Esmith/home.html
      http://ABC.com:/%7esmith/home.html

Based on my quick read of that and of http://www.ietf.org/rfc/rfc3986.txt, I think the proper thing to do is _not_ to strip the port, if it exists, _unless_ it is port 80. I recall being asked by someone else to respect port 8080 as a different URL. We should not transpose the port (like Drupal bootstrap does); we should instead allow it as part of the domain identifier string.

Thus, if passed the url : http://example.com:8080, DA should report that as is -- and you should 'register' that domain string. This opens the possibility that http://example.com and http://example.com:80 are equivalent (as in the specification) but http://example.com:8080 is not.

The other idea that this brings up is an "alias registration" that lets you assign alternative domain strings to a single domain. For example, you might register port 8080 as an alias of example.com.

ariflukito’s picture

We strip the port only for internal processing to allow DA to find matching configuration. We don't the strip the URI itself so I don't think the RFC is applied to us. It is web browser job to strip default port from URI. The advantage of not registering port number in DA is, when you moving from one host to another or changing your webserver port you don't need to change any configuration. It will just work.

This opens the possibility that http://example.com and http://example.com:80 are equivalent (as in the specification) but http://example.com:8080 is not.
Isn't that now we have this behavior? Or are you saying if we configure web server to listen on multiple ports instead of multiple web servers, then I think this is not in the specification.

I didn't know that http://ABC.com:/ is valid, what does $_SERVER['HTTP_HOST'] give when we enter this uri?

URI producers and normalizers should omit the port component and its ":" delimiter if
port is empty or if its value would be the same as that of the scheme's default.

I believe URI producers and normalizers here are web browsers, so they've already done stripping for us so http://ABC:com:/ will work.

I don't know about alias registration why do you want to have port 8080 as an alias? I cannot think of an example use case.

agentrickard’s picture

I am saying that people can configure their webservers so that example.com and example.com:8080 are different sites.

With the current logic, domain_init() would render example.com:8080 as 8080.example.com. With your patch, it would render as example.com. We probably just need to leave it alone as example.com:8080.

Currently, we do not account for this behavior.

ariflukito’s picture

My question is why would anyone makes those as different sites, doesn't seem logical to me.

agentrickard’s picture

Well, that's the standard. Here's an example.

For a while, I was running Ruby on Rails on LightPPD on my development machine. By default, Apache ran on localhost:80 and LightPPD ran on localhost:3000.

When you start talking about supporting non-standard configurations, you have to account for configurations that you might not use.

Now, I think that Drupal and DA already support non-standard ports. You just have to 'register' them differently.

If you look at the instructions for settings.php -- which DA copies -- you register port 8080 as 8080.example.com:

 * If you are installing on a non-standard port number, prefix the
 * hostname with that number. For example,
 * http://www.drupal.org:8080/mysite/test/ could be loaded from
 * sites/8080.www.drupal.org.mysite.test/.

Under this logic, DA already supports non-standard ports. If this doesn't work, then I might consider a patch. But I am hesitant to make changes to fix what might not be broken.

ariflukito’s picture

The setting in Drupal works but not in DA because DA uses the registered domain for the uri.

Ok let's reverse for example you have drupal running on LightPPD on port 3000 and you have something else running on Apache port 80. So drupal can be accessed from this uri http://example.com:3000. You put settings.php in sites/3000.example.com as per documentation. So far everything works.

Now DA, you register one affiliate site1.example.com and these are the different ways you can register it:
- 3000.site1.example.com (as settings.php)
- site1.example.com
- site1.example.com:3000

Now you try to access it through http://site1.example.com:3000. DA will look for 3000.site1.example.com.

First case, match found but the $_domain['path'] will be http://3000.site1.example.com. DA tries to redirect to that uri (drupal_goto($_domain['path']), there is where it fails.

Second and third case, match not found. DA will redirect to primary domain.

Without the patch none of them will work, with my patch the second case will work.

agentrickard’s picture

Yes. I agree. I'm wondering if we should separate the port the way we separate the scheme -- probably not.

agentrickard’s picture

Testing.

agentrickard’s picture

Status: Needs work » Needs review
StatusFileSize
new3.13 KB

OK. I tested this by enabling the following apache ports: 80, 8080, 3000. And it seems to work fine.

You now register the port as part of the domain:

example.com
example.com:8080
example.com:3000

Are all valid.

ariflukito’s picture

This patch for D6?

edit: nvm I checked out wrong branch
It works for me

agentrickard’s picture

The patch for D6 will be very very similar.

agentrickard’s picture

Status: Needs review » Fixed

Committed to HEAD and 5-dev.

Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

kenorb’s picture