1

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 example.email@gmail.com
        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
        </Directory>

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

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

        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

</VirtualHost>

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 Apr 29 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 Apr 29 at 10:07
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.

| improve this answer | |

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.