Apache vhosts config: Host Name instead of IP Address

5,503

Following DTest's tip I figured out that there was just a redirect from my domain provider. My domain provider did just a redirect instead of a real DNS A record entry to sub.example.com. Added the DNS A record and now "It works!". Thanks guys!

Share:
5,503

Related videos on Youtube

j7nn7k
Author by

j7nn7k

Hi, I'm Jannik, Entrepreneur and coder. Combining both in my current position as founder & CTO of Particulate. I studied at the University of Koblenz, Germany (MSc of Business and Computer Science). I'm interesed in technology, traveling, football and music

Updated on September 18, 2022

Comments

  • j7nn7k
    j7nn7k over 1 year

    I have a domain (example.com) hosted at an external provider. I directed the subdomain sub.example.com to my ubuntu server (12.04 with apache2).

    On my ubuntu server I have a vhost setup like this. The rest of the config is basically apache 2 standard:

    <VirtualHost *:80>
            ServerName sub.example.com
            ServerAlias sub.example.com
            ServerAdmin [email protected]
            DocumentRoot /var/www/sub.example.com
    
            ErrorLog ${APACHE_LOG_DIR}/error.log
            # Possible values include: debug, info, notice, warn, error, crit,
            # alert, emerg.
            LogLevel warn
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    
            WSGIScriptAlias / /home/application/sub.example.com/wsgi.py
    
            <Directory /home/application/sub.example.com>
                    <Files wsgi.py>
                            Order allow,deny
                            Allow from all
                    </Files>
            </Directory>
    </VirtualHost>
    

    When I enter http://sub.example.com in my browser my application shows up fine. But the domain is replaced by the IP address of my server. Do I have to configure my server somewhere else to deliver all its content under my domain sub.example.com?

    Here is my wsgi.py file:

    import os
    import sys
    from os.path import abspath, dirname, join
    
    
    PROJECT_ROOT = abspath(dirname(dirname(__file__)))
    GIT_ROOT = abspath(dirname(dirname(PROJECT_ROOT)))
    
    sys.path.insert(0, join(GIT_ROOT, 'venv', 'lib', 'python2.7', 'site-packages'))
    sys.path.insert(0, PROJECT_ROOT)
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xxx.settings")
    
    # This application object is used by any WSGI server configured to use this
    # file. This includes Django's development server, if the WSGI_APPLICATION
    # setting points here.
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    
    # Apply WSGI middleware here.
    # from helloworld.wsgi import HelloWorldApplication
    # application = HelloWorldApplication(application)
    
    • Kyle Smith
      Kyle Smith over 11 years
      You mean in the address bar?
    • ravi yarlagadda
      ravi yarlagadda over 11 years
      Most likely the Python application has a certain URL that it considers "canonical" (the IP address) and is redirecting requests to other domains to that URL. Is there any configuration in your application to manage that?
    • j7nn7k
      j7nn7k over 11 years
      Yes. I can also enter http://sub.example.com/page1 and get to the right page but then the address in the browser is rewritten to http://1.1.1.1/page1 . Where 1.1.1.1 is the ip of my server obviously :)
    • Derek Downey
      Derek Downey over 11 years
      It does sound like there's a redirect going on. Use your browser's developer tools (or firebug for firefox) to watch the network requests. You should see a 301 or 302 on the sub.example.com request, and probably a 200 on the IP request
    • j7nn7k
      j7nn7k over 11 years
      updated my post with the wsgi.py