Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualHost/DocumentRoot conflict when using mod_realdoc #6

Closed
andrewmackrodt opened this issue May 20, 2015 · 2 comments
Closed

VirtualHost/DocumentRoot conflict when using mod_realdoc #6

andrewmackrodt opened this issue May 20, 2015 · 2 comments

Comments

@andrewmackrodt
Copy link

We've tried deploying mod_realdoc and phpinc to production but have run across a problem with requests being handled by the wrong VirtualHost. Each VirtualHost has a unique DocumentRoot and port, the Apache configs are similar to:

<VirtualHost *:80>
    DocumentRoot /var/www/proj/env/docroot1
    ServerName secure.hostname.tld
    UseCanonicalName On

    <Directory /var/www/proj/env>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    <IfModule mod_php5.c>
        # The include_path replaces "/var/www/proj/env/docroot1" with DocumentRoot
        # when the php extension incpath is enabled, therefore the path must go up
        # one level, i.e. "/..". The initial include_path is also appended in case the
        # php extension gets disabled.
        php_value include_path ".:/var/www/proj/env/docroot1/../legacy/classes:/var/www/proj/env/HEAD/legacy/classes"

        # php incpath setting to resolve the correct DocumentRoot
        php_admin_value incpath.search_replace_pattern "/var/www/proj/env/docroot1"
    </IfModule>
</VirtualHost>

<VirtualHost *:24380>
    DocumentRoot /var/www/proj/env/docroot2
    ServerName secure.hostname.tld
    UseCanonicalName On

    <Directory /var/www/proj/env>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    <IfModule mod_php5.c>
        # The include_path replaces "/var/www/proj/env/docroot2" with DocumentRoot
        # when the php extension incpath is enabled, therefore the path must go up
        # one level, i.e. "/..". The initial include_path is also appended in case the
        # php extension gets disabled.
        php_value include_path ".:/var/www/proj/env/docroot2/../legacy/classes:/var/www/proj/env/HEAD/legacy/classes"

        # php incpath setting to resolve the correct DocumentRoot
        php_admin_value incpath.search_replace_pattern "/var/www/proj/env/docroot2"
    </IfModule>
</VirtualHost>

Deployments are done via rsync with the --link-dist option, deployments reside in /var/www/proj/env/hash with symlinks created to point to the new HEAD:

$ ls -al /var/www/proj/env/
drwxr-xr-x 72ac812
lrwxrwxrwx docroot1 -> 72ac812/docroot1
lrwxrwxrwx docroot2 -> 72ac812/docroot2
lrwxrwxrwx HEAD -> 72ac812

DocumentRoot used to be HEAD (e.g. DocumentRoot /var/www/proj/env/HEAD/docroot1) but was changed to use the {docroot1,docroot2} links in case they fixed the problem

A couple of seconds after reloading the server, lots of 404 and 'File does not exist' errors are logged. The detailed error suggests that requests going to :80 are being resolved to the DocumentRoot served by :24380: File does not exist: /var/www/proj/master/ff8c48a/docroot2/js. Unloading mod_realdoc (by removing realdoc.conf) and reloading apache instantly stops more errors from happening.

This is happening on a CentOS 6.x / Apache 2.2.15 (prefork) server. Throughout is about 850rpm.

@benburry
Copy link

I believe your issue is caused by a key clash when storing the docroot/time values.

Realdoc includes the server name and port to avoid clashes between virtualhosts, using ap_get_server_name and ap_get_server_port. However, in order for ap_get_server_port to return anything but the default, your ServerName must include the port number, or you'll need to add a UseCanonicalPhysicalPort directive to each VirtualHost.

I think the simplest change is to add a UseCanonicalPhysicalPort On line.

I realise it's a long time since you filed this issue, but if you're able to confirm this resolves your problem then we can get something added to the readme to reflect it.

See this issue for an example of the ap_get_server_port issue.

@andrewmackrodt
Copy link
Author

Thanks for the reply benburry, apologies in the long delay to respond. This was caused by the omission of UseCanonicalPhysicalPort as you correctly pointed out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants