在Apache和WSGI Django的部署 [英] Deploying Django on Apache and WSGI

查看:212
本文介绍了在Apache和WSGI Django的部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我已经发现使用WSGI但INFACT一堆技术支持过度的Apache Django部署他们都弄得我很遗憾,我不能让Django的运行。我希望这是真正的轻松的工作,但被我面对困难的新来者。

我有两个Django的项目,即WEBSITE1和WEBSITE2我的 /主页/齐亚/文件/ codeS / Django的内/ WEBSITE1 的和的 ... /网站2 的DIR分别。含有settings.py文件的文件夹是的根/ 的里面的 / WEBSITE1 的和的 /网站2 的目录。

的Apache,根据需要的mod_wsgi一切已安装。如何编辑apache2.conf和wsgi.py文件,以保持这两个项目运行在端口8080和8081?

我这个问题过去几天挣扎,已经尝试了所有以下网站。

LINK1 ,的链接2 ,的 LINK3 ,<一个href=\"https://www.digitalocean.com/community/tutorials/how-to-run-django-with-mod_wsgi-and-apache-with-a-virtualenv-python-environment-on-a-debian-vps\"相对=nofollow> LINK4


UPDATE1:

我从一开始就遵循以下做法正确,使事情进展顺利,但发现自己在一些新的问题。请指引我哪里错了。


  1. 安装MOD-WSGI和Apache2的:
    命令和apt-get安装中的libapache2-MOD-WSGI和放大器;&安培; sudo易于得到更新和放大器;&安培; sudo易于得到安装的Apache2

  2. 编辑apache2的端口8083,而不是80通过改变文件/etc/apache2/ports.conf:收听8083

  3. 添加以下行的/ etc / hosts文件: 160.75.133.175 160.75.133.175

  4. 编辑以下code。在/etc/apache2/apache2.conf中文件:

&LT;目录/&GT;
        选择了FollowSymLinks索引
        设置AllowOverride无
        要求所有批准
&LT; /目录&GT;


  • 创建一个文件中在/ etc / apache2的/网站的可用/目录名称为sql_api.conf:

  • &LT;虚拟主机*:8083&GT;
        的ServerAdmin zia@gmail.com
        服务器名160.75.133.175
        ServerAlias​​ http://160.75.133.175
        &LT;目录为/ home /齐亚/文件/ codeS / Django的/ sql_api /&GT;
                为了否认,允许
                所有允许
        &LT; /目录&GT;
        WSGIScriptAlias​​ / /home/zia/Documents/$c$cs/Django/sql_api/root/wsgi.py
        WSGIDaemonProcess 160.75.133.175用户= WWW的数据组= www数据线= 25蟒蛇路径= /家庭/齐亚/文件/ codeS / Django的/ sql_api /根/:在/ usr
        WSGIProcessGroup 160.75.133.175
        错误日志/home/zia/Documents/$c$cs/Django/sql_api/root/error.log
    &LT; /虚拟主机&GT;

    <醇开始=6>
  • 运行下列命令中的在/ etc / apache2的/站点可用DIR是:须藤a2enmod WSGI和放大器;&安培;须藤a2ensite sql_api.conf&放大器;&安培;须藤服务的Apache2重启

  • 开启 http://160.75.133.175:8083/ 但得到以下错误:
    内部服务器错误
    服务器遇到内部错误或配置错误,无法完成您的请求。
    请致电zia@gmail.com服务器管理员,告知他们这个错误发生的时间,你只是这个错误之前执行的操作。
    关于这个错误的更多信息可在服务器错误日志。
    在160.75.133.175端口8082的Apache / 2.4.7(Ubuntu的)服务器

  • 注意:当我想提出一个Django项目中的 /无功/网络/ 的目录,然后做同样的方式再努力就好了!我想是因为我试图访问的 /主页/齐亚/....目录,有这个问题。不管怎么说,这只是一个猜测。我想AP preciate你的帮助。


    解决方案

    你应该刚刚开始,如果你做了一堆修改Apache配置的。我最熟悉与Ubuntu下设置。

    您需要什么看做的是安装apache下这两个网站作为一个虚拟主机。安装Apache后,有一个文件夹,名为网站,提供网站启用应​​包含与您的网站项目的名称的虚拟主机文件。每一个虚拟主机将指向徘徊无论你.wsgi文件的位置。这些虚拟主机通常在相同的端口号听(丹尼尔如上所述),但服务是基于域名的任何应用要求。 noobmovies.com google.com等...

    如何设置与Apache虚拟主机是在这里很好地解释pretty。这个假定你使用Ubuntu虽然。

    <一个href=\"https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts\" rel=\"nofollow\">https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

    您的虚拟主机(该文件应当域进出口... noobmovies.com的名字命名),并期待这样的事情...

      ** LT;虚拟主机*:8080&GT;
        的ServerAdmin your_admin_email@gmail.com
        服务器名www.yourdomain.com
        ServerAlias​​ yourdomain.com    &LT;目录为/ home /路径/你/项目/&GT;
                为了否认,允许
                所有允许
        &LT; /目录&GT;    WSGIScriptAlias​​ / /home/path/your/project/app/wsgi.py
        WSGIDaemonProcess yourdomain.com用户= WWW的数据组= www数据线= 25蟒蛇路径= /路径/要/你/项目/应用/:/路径/要/蟒蛇/虚拟/主机/站点包
        WSGIProcessGroup yourdomain.com
        错误日志/path/to/your/app/error.log
    &LT; /虚拟主机&GT; **

    记住WSGIDaemonProcess仅仅是如果你使用的virtualenv运行你的应用程序(你应该)。这告诉Apache在哪里蟒蛇是应该用于读取WSGI应用程序/运行Django应用程序。

    因此​​,如果你使用Ubuntu或Linux,你可能只是想卸载Apache和重新安装后按照数字海洋指令来获取设置。

    Although I have found a bunch of tech support to deploy Django over Apache using WSGI but infact they all have confused me unfortunately, and I couldn't get the Django running. I hope this to be real easy job but being a new comer I am facing difficulties.

    I have two Django projects namely website1 and website2 inside my /home/zia/Documents/Codes/Django/website1 and ..../website2 dir, respectively. The folder containing settings.py file is root/ inside the /website1 and /website2 dir.

    Apache, mod_wsgi everything is installed as required. How to edit apache2.conf and wsgi.py file to keep these two projects running over port 8080 and 8081?

    I am struggling with this issue for past few days and have tried all the following websites.

    link1,link2,link3,link4


    UPDATE1:

    I have followed the following approach right from the beginning to make things going well but found myself in some new issues. Kindly guide me where I am wrong.

    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":

    <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. Run the following commands being in "/etc/apache2/sites-available" dir: sudo a2enmod wsgi && sudo a2ensite sql_api.conf && sudo service apache2 restart
    2. Open http://160.75.133.175:8083/ but getting the following error: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at zia@gmail.com to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. Apache/2.4.7 (Ubuntu) Server at 160.75.133.175 Port 8082

    NOTE: When I am making a Django project in /var/www/ dir and then doing the same approach then working just fine! I think because I am trying to access /home/zia/.... dir, there is this issue. Anyways, this is just a guess. I would appreciate your help.

    解决方案

    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.

    这篇关于在Apache和WSGI Django的部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆