So i've got a website hosted at example.com and I want it to work with www.example.com.

I've got a CNAME entry in my DNS for www pointing to example.com.

My virtual host config looks like this:

<VirtualHost *:80>

        ServerAdmin [email protected]
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Alias /static /home/ubuntu/example/example/static
        <Directory /home/ubuntu/example/example/static>
                Require all granted

         Alias /media /home/ubuntu/example/example/media
        <Directory /home/ubuntu/example/example/media>
                Require all granted

        <Directory /home/ubuntu/example/example/example>
                <Files wsgi.py>
                        Require all granted

        WSGIScriptAlias / /home/ubuntu/example/example/example/wsgi.py
        WSGIDaemonProcess django_app  python-path=/home/ubuntu/example/example python-home=/home/ubuntu/example/example/venv
        WSGIProcessGroup django_app


I'm not sure what's wrong because to me it looks like everything is configured correctly.

Any tips?

  • "400 Bad Gateway" - Do you mean "Bad Request"? ("Bad Gateway" is 502)? FWIW, what you've posted looks OK to me. Could your Django app be triggering this response?
    – DocRoot
    Commented Apr 29, 2020 at 10:00
  • 1
    Sorry yes you're right. It's a Bad Request error. I'd not considered it being a Django issue to be honest.
    – Chaostime
    Commented Apr 29, 2020 at 10:07

1 Answer 1


Thanks to DocRobot, it ended up being a Django issue.

FWIW, the settings in a Django project have an allowed hosts sections. I'd only entered the hostname of the hosting server, example.com, where as it should have also added www.example.com.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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