1

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 admin@sub.example.com
        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)
j7nn7k
  • 131
  • 2
  • 9
  • You mean in the address bar? – Kyle Smith Aug 31 '12 at 15:22
  • 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? – Shane Madden Aug 31 '12 at 15:25
  • 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 :) – j7nn7k Aug 31 '12 at 15:25
  • @ShaneMadden it's a standard django app. I did not configure anything domain or url related specifically... – j7nn7k Aug 31 '12 at 15:30
  • 2
    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 – Derek Downey Aug 31 '12 at 15:38
  • Yeah right. I see a 302. What could be the cause for that? – j7nn7k Aug 31 '12 at 15:41
  • `cat wsgi.py`?? – quanta Aug 31 '12 at 15:48
  • updated my post with the wsgi.py – j7nn7k Aug 31 '12 at 15:52

1 Answers1

1

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!

j7nn7k
  • 131
  • 2
  • 9