简体   繁体   English

无法使用apache mod WSGI在ubuntu上部署Django

[英]unable to deploy Django on ubuntu with apache mod WSGI

I am using ubuntu 12.04 and I did the following: 我正在使用ubuntu 12.04,并且执行了以下操作:

sudo apt-get install python-mysql 须藤apt-get install python-mysql

sudo python setup.py install (install Django 1.6.2) sudo python setup.py install(安装Django 1.6.2)

sudo apt-get install mysql-server-... 须藤apt-get install mysql-server -...

sudo apt-get install apache2 须藤apt-get install apache2

sudo apt-get install libapache2-mod-wsgi 须藤apt-get install libapache2-mod-wsgi

Here are my configuration files: 这是我的配置文件:

/home/firstweb.wsgi: /home/firstweb.wsgi:

import os
import sys
sys.path = ['/var/www/firstweb'] + sys.path
os.environ['DJANGO_SETTINGS_MODULE'] = 'firstweb.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

/etc/apache/sites-availables/firstweb.conf: /etc/apache/sites-availables/firstweb.conf:

<VirtualHost *:80>
WSGIScriptAlias / /home/adel/firstweb.wsgi
ServerName firstweb.com
Alias /static /var/www/firstweb/static/

<Directory /var/www/firstweb/>
order allow,deny
Allow from all
</Directory>
</VirtualHost>

then I did: 然后我做了:

  1. a2ensite firstweb.conf
  2. cd /var/www/
  3. django-admin.py startproject firstweb
  4. apachectl restart
  5. vi /etc/hosts

and add the following ( 192.168.0.123 is my wlan ip) 并添加以下内容( 192.168.0.123是我的wlan ip)

192.168.0.123 firstweb.com

I use mysql and I create a database and change the settings.py and the syncdb works fine 我使用mysql并创建数据库并更改settings.pysyncdb正常运行

But when I enter the www.firstweb.com in browser the default page of Apache appears (it works....) 但是,当我在浏览器中输入www.firstweb.com时,将显示Apache的默认页面(有效。。。)

and the Django default page does not appear!! 并且Django默认页面没有出现!

what is wrong with my configuration? 我的配置有什么问题?

thank you. 谢谢。

Your virtual server is not listening on www.firstweb.com, only on firstweb.com. 您的虚拟服务器不在www.firstweb.com上监听,而仅在firstweb.com上监听。 You should add a ServerAlias directive for the www version. 您应该为www版本添加ServerAlias指令。

The path your WSGIScriptAlisa directive is referring to, is not within any directory you specified to the Directory directive indicating where Apache was allowed to serve files/scripts from. WSGIScriptAlisa指令所引用的路径不在您为Directory指令指定的任何目录中,该目录指示允许Apache从何处提供文件/脚本。 Further, the Apache user would not normally be able to access files under a user home directory. 此外,Apache用户通常将无法访问用户主目录下的文件。 Both problems would cause different Forbidden HTTP responses. 这两个问题都会导致不同的“禁止的HTTP”响应。 So, even you solve your ServerName/ServerAlias and host issues, you would likely then have those problems. 因此,即使您解决了ServerName / ServerAlias和主机问题,也很可能会遇到这些问题。 make sure you go read the official mod_wsgi deployment docs on the Django site. 确保您阅读了Django网站上的官方mod_wsgi部署文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM