• 超简单系列:ubuntu 13.04 安装 apache2.2+mod_wsgi+Django


    1,Ubuntu更新系统

    sudo apt-get update
    sudo apt-get upgrade

    2,安装apache,mod_wsgi,Django

    sudo apt-get install apache2 libapache2-mod-wsgi  python-django

    更多Ubuntu系统内置安装包请搜索:Ubuntu Packages Search

    3,配置Django环境

    sudo mkdir  /opt/wwwroot
    
    cd /opt/wwwroot
    sudo django-admin startproject hello

        创建wsgi文件

    sudo mkdir /opt/wwwroot/hello/apache
    sudo vi /opt/wwwroot/hello/apache/django.wsgi

        文件django.wsgi贴入下面内容

    django.wsgi内容
    import os
    import sys
    sys.path.append('/opt/wwwroot')
    sys.path.append('/opt/wwwroot/hello')
    path = '/opt/wwwroot'
    
    if path not in sys.path:
        sys.path.insert(0, '/opt/wwwroot')
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'hello.settings'
    
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()

    4,创建一个新的apache站点

    sudo vi /etc/apache2/sites-available/hello
    hello内容
    <VirtualHost *:80>
    
        ServerName hello.com
        DocumentRoot /opt/wwwroot/hello
    
        <Directory /opt/wwwroot/hello>
            Order allow,deny
            Allow from all
        </Directory>
        Alias /robots.txt /opt/wwwroot/hello/robots.txt
        Alias /favicon.ico /opt/wwwroot/hello/favicon.ico
        Alias /images /opt/wwwroot/hello/images
        Alias /static /opt/wwwroot/hello/static
    
        WSGIDaemonProcess hello.com processes=2 threads=15 display-name=%{GROUP}
        WSGIProcessGroup hello.com
        WSGIScriptAlias / /opt/wwwroot/hello/apache/django.wsgi
    
     </VirtualHost>

       激活hello站点

    sudo a2ensite hello
    sudo service apache2 reload

    5,设置完毕打开浏览器进入输入ip地址,就可以看到Django欢迎界面了。

    6.  如果发现文件访问不了,权限的问题

    sudo chown -R (group).(user)  (your project dir)

    Django官网部署链接:https://docs.djangoproject.com/en/1.2/howto/deployment/

  • 相关阅读:
    python爬虫 -掘金
    python 爬取简书评论
    python爬取知乎评论
    python 爬取链家
    python爬虫获取下一页
    python正则找到字符串里面的数字
    faker切换user-agent
    python 爬虫可视化函数,可以先看看要爬取的数据是否存在
    acwing 471. 棋盘 解题记录
    ACWING 95 费解的开关 解题记录
  • 原文地址:https://www.cnblogs.com/smallcoderhujin/p/3655662.html
Copyright © 2020-2023  润新知