0

I have a CentOS 7 server with about 20 domains all managed automatically with a vhosts file in /etc/httpd/conf.d.

I am trying to learn Django and wanted to set up a single domain using it, so I added a specific virtualhost to the .conf file.

The result is that the Django domain works fine but all the other sites are broken (try to use Django but cause errors).

The Django domain has two folders: djangodomain.com for static files and djangodomain.app for the Python files.

How can I integrate a single Django domain into my existing many-domain virtual host setup?

Existing vhosts.conf:

<VirtualHost *:80>
    serveradmin username@domain.com
    serveradmin username@domain.com

    usecanonicalname off

    # www.site.com » site.com
    rewriteengine on
    rewritecond %{HTTP_HOST}    ^www\.(.*)$ [nc]
    rewriterule ^(.*)$          http://%1   [r=301,l]

    # file locations
    virtualdocumentroot "/home/username/%0"

    <directory "/home/username/*">
        allowoverride all
        require all granted
        options indexes followsymlinks
        options +execcgi
        options +includes
    </directory>
</VirtualHost>

What I added that broke all but the Django site:

<VirtualHost djangodomain.com:80>
    ServerName djangodomain.com
    ServerAlias www.djangodomain.com
    ServerAdmin user@domain.com

    DocumentRoot /home/username/djangodomain.com

    WSGIScriptAlias / /home/username/djangodomain.app/django.wsgi

    <Directory /home/username/djangodomain.app>
        Order allow,deny
        Allow from all
    </Directory>

    Alias /robots.txt /home/username/djangodomain.com/robots.txt
    Alias /favicon.ico /home/username/djangodomain.com/favicon.ico
    Alias /images /home/username/djangodomain.com/images
    Alias /static /home/username/djangodomain.com/static

    ErrorLog /home/username/djangodomain.logs/error.log
    CustomLog /home/username/djangodomain.logs/access.log combined
</VirtualHost>

[update: problem solved] Crossposted to Stack Exchange

  • What does apachectl configtest say? – Jake Oct 21 '16 at 19:48
  • Syntax OK, not much else of interest. I solved my problem by changing <VirtualHost djangodomain.com:80> to <VirtualHost *:80> and putting the Django part after the dynamic part. – Andrew Swift Oct 24 '16 at 14:01
0

You can't combine a VirtualHost on the same IP address and port without any ServerName or ServerAlias settings, with one that does have them. You can run apachectl -S to see what Apache actually thinks about that config.

Assuming you know all the 20 domain names used to access your default virtual host, the solution is simply to list them all there using ServerName / ServerAlias. If you don't, then you can e.g. sequester the new one to a different IP address and/or port.

  • I was able to combine them by putting the more specific VirtualHost second. I need to keep the dynamic domain names because I'm always adding and removing domains and subdomains and it's MUCH easier to have the server just follow the existence of folders. That's how Tumblr does their custom subdomains (at least how they used to do it). – Andrew Swift Oct 24 '16 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.