Apache mod_wsgi更好的配置

时间:2017-09-15 10:57:56

标签: django apache mod-wsgi

我正在使用apache mod_wsgi部署基于django的网络应用程序。这是我的虚拟主机:

<VirtualHost _default_:*>

    ServerAdmin my_email@emails.com
    DocumentRoot /var/www/appWSGI/gestioner/gestioner/

    Alias /static /var/www/appWSGI/gestioner/static/

    <Directory /var/www/appWSGI/gestioner/>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>

    WSGIDaemonProcess gestioner python-path=/var/www/appWSGI/gestioner python-home=/var/www/appWSGI/env
    WSGIProcessGroup gestioner
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptAlias / /var/www/appWSGI/gestioner/gestioner/wsgi.py
    WSGIPassAuthorization On
</VirtualHost>

这个基本配置工作正常。我想知道是否可以改进这个可能还有其他指令,我不知道... 可以使用另一种启动性能的配置吗?

提前谢谢大家!!

1 个答案:

答案 0 :(得分:0)

import os
from django.core.wsgi import get_wsgi_application
import sys   
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_project.settings")
application = get_wsgi_application()

如果您使用的是python2

  

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

如果您使用的是python3

  

sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3

然后是apache配置

<VirtualHost *:80>
    ServerName dev.example.com #your server name
    ServerAlias dev.example.com #your server alias

    DocumentRoot #your document root
    WSGIProcessGroup dev.example.com
    WSGIPassAuthorization On
    WSGIDaemonProcess dev.example.com python-home=/home/robert/django/robertenv python-path=/home/robert/django/
    WSGIScriptAlias /backend /home/robert/django/project/wsgi.py process-group=dev.example.com

    Alias "/uploads" "/home/robert/django/uploads" #uploads directory

    <Directory #your document root>
            Require all granted

            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} -s [OR]
            RewriteCond %{REQUEST_FILENAME} -l [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^.*$ - [NC,L]

            RewriteRule ^(.*) /index.html [NC,L]
    </Directory>

    <Directory /home/robert/django/uploads>
        Require all granted
    </Directory>

    <Directory /home/robert/django/project>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>

来源apache2 wsgi consource1