• apache部署mo_python


    一,安装 mod_wsgi

    sudo apt-get install apache2-threaded-dev

    sudo apt-get install apache2 libapache2-mod-wsgi

    django 最新版已经不支持mod_python,所以mod_wsgi是最好的选择

    增加apache配置端口:

      修改/etc/apache/site-available/python

      

    <VirtualHost *:801>
        ServerAdmin webmaster@localhost
        
        DocumentRoot /var/www/python/
        <Directory />
            Options FollowSymLinks
            AllowOverride ALl
        </Directory>
        <Directory /var/www/python>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>
        
        WSGIScriptAlias / "/var/www/python/server/server/wsgi.py"
    
    
        ErrorLog ${APACHE_LOG_DIR}/py.error.log
    
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
    
        CustomLog ${APACHE_LOG_DIR}/py.access.log combined
    
        Alias /doc/ "/usr/share/doc/"
        <Directory "/usr/share/doc/">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride None
            Order deny,allow
            Deny from all
            Allow from 127.0.0.0/255.0.0.0 ::1/128
        </Directory>
    
    </VirtualHost>

      增加端口 修改 /etc/apache2/ports.conf

      使配置生效:sudo a2ensite python

      进入/var/www/python

      django-admin.py startproject server

      修改var/www/python/server/server/wsgi.py 加入环境变量:

      

    """
    WSGI config for server project.
    
    It exposes the WSGI callable as a module-level variable named ``application``.
    
    For more information on this file, see
    https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/
    """
    import os
    import sys
    
    path = '/var/www/python/server'
    if path not in sys.path:
        sys.path.append(path)
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings")
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()

    打开网址查看效果:

      localhost:801

    查看localhost:801/admin发现格式乱码。原来django的admin模块CSS路径在python引入模块路径下:

    import django

    print django.__file__

    output:

    '/usr/local/lib/python2.7/dist-packages/Django-1.8.dev20140828064426-py2.7.egg/django/__init__.pyc'

    故css路径如下:

    /usr/local/lib/python2.7/dist-packages/Django-1.8.dev20140828064426-py2.7.egg/django/contrib/admin/static

     

    重新配置apache 在其中加上:

        Alias /static/ "/usr/local/lib/python2.7/dist-packages/Django-1.8.dev20140828064426-py2.7.egg/django/contrib/admin/static/"
    
        
        <Directory /usr/local/lib/python2.7/dist-packages/Django-1.8.dev20140828064426-py2.7.egg/django/contrib/admin/static/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>

    重启apach2,打开localhost:801/admin 就可以看到久违的css格式。

    apache命令分析:

    Alias   路径别名。

    Options Indexes FollowSymLinks MultiViews

     

  • 相关阅读:
    (原创)代码分析-DataGrid实现增删(带提示)改和分页
    (原创)webform页面间传值的特殊方法
    (原创)如何把数据放到web不能访问的文件夹中并给用户下载?
    MediaWiki如何重置用户密码
    伟大的程序员是怎样炼成的?
    Java多线程(一)、多线程的基本概念和使用
    Android杂谈Activity、Window、View的关系
    Android LayoutInflater学习
    10条不可不知的手机礼仪 看看你犯过哪几项?
    Java支持的字符集[Code]
  • 原文地址:https://www.cnblogs.com/canbefree/p/3942330.html
Copyright © 2020-2023  润新知