1

I'm setting up a django web application and I'm using github for version management. So I need a testing page. How do I achieve this?

I've found this question: Is it possible to host multiple django projects under the same domain?

But it's 6 years old, I would prefer to host it under a sub-domain and I have no idea what the answer is talking about, since I'm new to Django.

Jojo
  • 409
  • 1
  • 6
  • 11

2 Answers2

2

Yes, it is possible. I run a LAMP Stack on my DigitalOcean droplet that hosts a dozen live django websites. It's all really focused around your virtual environment setup in your site configuration.

Here is an example, that if you study should be enough to get you going... /etc/apache2/sites-available/website1.com.conf

<VirtualHost *:80>

        ServerName website1.com
        ServerAlias www.website1.com

        ServerAdmin youremail@domain.com
        DocumentRoot /var/www/html/website1.com/djangoproject
        WSGIScriptAlias / /var/www/html/website1.com/djangoproject/djangoproject/wsgi.py

        WSGIDaemonProcess website1.com processes=2 threads=15 display-name=%{GROUP} \
                python-home=/var/www/html/website1.com/venv \
                python-path=/var/www/html/website1.com/ainet
        WSGIProcessGroup website1.com

        <Directory/var/www/html/website1.com/djangoproject>
                AllowOverride all
                Require all granted
                Options FollowSymlinks
        </Directory>

        Alias /static/ /var/www/html/website1.com/djangoproject/static/

        <Directory /var/www/html/website1.com/djangoproject/static/>
                Require all granted
        </Directory>

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

</VirtualHost>

/etc/apache2/sites-available/website2.com.conf

<VirtualHost *:80>

        ServerName subdomain.website1.com
        ServerAlias subdomain.website1.com

        ServerAdmin youremail@domain.com
        DocumentRoot /var/www/html/subdomain.website1.com/djangoproject
        WSGIScriptAlias / /var/www/html/subdomain.website1.com/djangoproject/djangoproject/wsgi.py

        WSGIDaemonProcess subdomain.website1.com processes=2 threads=15 display-name=%{GROUP} \
                python-home=/var/www/html/subdomain.website1.com/venv \
                python-path=/var/www/html/subdomain.website1.com/ainet
        WSGIProcessGroup subdomain.website1.com

        <Directory/var/www/html/subdomain.website1.com/djangoproject>
                AllowOverride all
                Require all granted
                Options FollowSymlinks
        </Directory>

        Alias /static/ /var/www/html/subdomain.website1.com/djangoproject/static/

        <Directory /var/www/html/subdomain.website1.com/djangoproject/static/>
                Require all granted
        </Directory>

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

</VirtualHost>

The above assumes that you put your django project in /var/www/html/website1.com/. It also assumes this same folder contains your virtual environment located in the venv folder.

/var/www/html/website1.com
/var/www/html/website1.com/djangoproject
/var/www/html/website1.com/venv
/var/www/html/subdomain.website1.com
/var/www/html/subdomain.website1.com/djangoproject
/var/www/html/subdomain.website1.com/venv

However, if you need a testing page as you say, Django has a built in local development server that I highly recommend you use.

Once you've got your environment set up it's as easy as running python manage.py runserver.

addohm
  • 2,248
  • 3
  • 14
  • 40
0

If you want to host on a subdomain, from the same server, I have done so using Nginx as a reverse proxy. It's pretty easy to set up, and you can get it to point requests to different subdomains to different instances of whatever server is running your django stuff.

Have a look at this: https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-web-server-and-reverse-proxy-for-apache-on-one-ubuntu-14-04-droplet You can replace 'apache' with any server that you want, obviously.

Alex
  • 2,270
  • 3
  • 33
  • 65
  • I only have access to one port though, since I'm on a VPS. I'll try to contact the host, but is there a way without having to use a different port? – Jojo Feb 19 '19 at 17:52