0

I have a Linux server (Ubuntu) and am trying to set up apache, but the server is not running my actual Django server but instead running an html file in var/www/html. Running

sudo systemctl reload apache2

works fine, so I think the problem involves the .conf file in /etc/apache2/sites-available/ called infosum.conf somehow.

This is for a new Linux server (Ubuntu). The project is running python3 Django 2.2 and apache 2.4 with mod-wsgi. When running

python manage.py runserver 0.0.0.0:8000

, the server works fine, but when on the apache server it just returns that HTML file.

/etc/apache2/sites-available/infosum.conf (infosum is project name)

Alias /static/ /home/username/infosum/staticfiles
<Directory /home/username/infosum/staticfiles>
    Require all granted
</Directory>
Alias /media/ /home/username/infosum/media/
<Directory /home/username/infosum/media>
    Require all granted
</Directory>
<Directory /home/username/infosum/infosum>
     <Files wsgi.py>
           Require all granted
      </Files>
</Directory>
WSGIScriptAlias / /home/username/infosum/infosum/wsgi.py
WSGIDaemonProcess django_app python-path=/home/username/infosum python-home=/home/username/infosum/venv
        WSGIProcessGroup django_app

/home/username/infosum/infosum/wsgi.py

import os
import sys
sys.path.append('/home/username/infosum/infosum')

# add the virtualenv site-packages path to the sys.path
sys.path.append('/home/username/infosum/venv/Lib/site-packages')
from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'infosum.settings')

application = get_wsgi_application()

UPDATE: I just ran

sudo a2ensite infosum

and it worked in, I think, getting the site up. One problem, there is a 500 server error and when running

sudo tail -f /var/log/apache2/error.log

I get

ImportError: No module named django.core.wsgi
MaisyDoge13
  • 154
  • 1
  • 3
  • 14
  • Most likely an issue related to SELinux and/or permissions, and not it‘s fault by any means. You ***really*** do not want a Webserver to be able to read files of a user‘s home directory. I am pretty sure that in Ubuntu, as in any other halfway reasonable Linux distribution, there is a default place on where to put your content. Read the according docs. – Markus W Mahlberg Jul 01 '19 at 05:54
  • Hint: to circumvent some of the (security) issues I see at the horizon, use Docker. It takes away your painpoints while not compromising system security (admittedly, this is questioned by some). See https://www.caktusgroup.com/blog/2017/03/14/production-ready-dockerfile-your-python-django-app/ for a QuickStart. – Markus W Mahlberg Jul 01 '19 at 05:58
  • @Markus So you are suggesting that I put the project into another folder(not in the home directory)? Can you provide a link to mentioned docs? – MaisyDoge13 Jul 01 '19 at 06:06
  • Uhm... I have *literally* no clue about how Ubuntu deals with that kind of stuff, but usually it is something like `/var/www/html/[yourVirtualHostIfYouHappenToHaveOne]`. You should be able to dig up the according docs, though. A quick google search gave me [a decent configuration primer](https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts). – Markus W Mahlberg Jul 01 '19 at 06:14
  • However, I can not stress enough that unless you ***really*** know what you are doing, fiddling with security related settings is a good way to ask for serious trouble later down the road. – Markus W Mahlberg Jul 01 '19 at 06:16
  • 1
    Did you symlink that conf file to sites-enabled? or run a2ensite? – Daniel Roseman Jul 01 '19 at 08:22

1 Answers1

0

OK i got it. First I ran

a2ensite /etc/apache2/sitesavailable/infosum

and updated the wsgi.py file from

sys.path.append('/home/username/infosum/venv/Lib/site-packages')

to

sys.path.append('/home/username/infosum/venv/lib/python3.7/site-packages')
MaisyDoge13
  • 154
  • 1
  • 3
  • 14