Deploying Django on Apache and WSGI

大兔子大兔子 提交于 2019-12-05 18:44:57

you should probably just start over if you made a bunch of changes to your Apache config. I'm most familiar with setups under Ubuntu.

What you need to look to do is setup both sites under apache as a virtual host. After installing apache there is a folder called sites-available and sites-enabled they should contain the virtual host files with the names of your website projects. Each virtual host will point to whereever your .wsgi file is located. these virtual hosts typically listen under the same port number (as Daniel mentioned above) but serve whichever app is requested based on the domain name. noobmovies.com google.com ect...

how to setup a virtual host with apache is pretty well explained here. this assumes you're using ubuntu though.

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

your virtual host (the file should be named after your domain exp... noobmovies.com) and will look something like this...

**<VirtualHost *:8080>
    ServerAdmin your_admin_email@gmail.com
    ServerName  www.yourdomain.com
    ServerAlias yourdomain.com

    <Directory /home/path/your/project/ >
            Order deny,allow
            Allow from all
    </Directory>

    WSGIScriptAlias / /home/path/your/project/app/wsgi.py
    WSGIDaemonProcess  yourdomain.com user=www-data group=www-data threads=25 python-path=/path/to/your/project/app/:/path/to/python/virtual/host/site-packages
    WSGIProcessGroup yourdomain.com
    ErrorLog /path/to/your/app/error.log
</VirtualHost>**

keep in mind the WSGIDaemonProcess is only if you're running your app using virtualenv (which you should). this tells apache where python is that should be used to read the wsgi app/run django app.

So if you're using ubuntu or linux you may just want to uninstall apache and reinstall then just follow the digital ocean instructions to get setup.

Thanks to everyone. Finally found a working procedure. Follow the following steps in order:

  1. Installing mod-wsgi and apache2: sudo apt-get install libapache2-mod-wsgi && sudo apt-get update && sudo apt-get install apache2
  2. Edit the apache2 port to 8083, instead of 80 by altering file "/etc/apache2/ports.conf": Listen 8083
  3. Add the following line into "/etc/hosts" file: 160.75.133.175 160.75.133.175
  4. Edit the following code in the "/etc/apache2/apache2.conf" file:

<Directory /> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>

  1. Create a file inside "/etc/apache2/sites-available/" dir with name "sql_api.conf" (make as many .conf files you want with different names, each serving different website):

<VirtualHost *:8083> ServerAdmin zia@gmail.com ServerName 160.75.133.175 ServerAlias http://160.75.133.175 <Directory /home/zia/Documents/Codes/Django/sql_api/ > Order deny,allow Allow from all </Directory> WSGIScriptAlias / /home/zia/Documents/Codes/Django/sql_api/root/wsgi.py WSGIDaemonProcess 160.75.133.175 user=www-data group=www-data threads=25 python-path=/home/zia/Documents/Codes/Django/sql_api/root/:/usr WSGIProcessGroup 160.75.133.175 ErrorLog /home/zia/Documents/Codes/Django/sql_api/root/error.log </VirtualHost>

  1. Add the following lines in the wsgi.py file inside "/home/zia/Documents/Codes/Django/sql_api/root/": sys.path.append('/home/zia/Documents/Codes/Django/sql_api/root') sys.path.append('/home/zia/Documents/Codes/Django/sql_api')
  2. Run the following commands being in "/etc/apache2/sites-available" dir: sudo a2enmod wsgi && sudo a2ensite sql_api.conf && sudo service apache2 restart
  3. Open http://160.75.133.175:8083/
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!