OS X启动时自动启动Django FastCGI

时间:2011-12-06 01:18:58

标签: django macos nginx fastcgi

我让Django FastCGI / nginx在OS X上运行良好。我从终端开始我的FastCGI进程,如下所示:

python manage.py runfcgi host=127.0.0.1 port=8000 --settings=settings

在我的nginx.conf文件中我有:

server {
    listen       8080;
    server_name  localhost;
    location / {
        fastcgi_pass 127.0.0.1:8000;

我使用launchd自动启动nginx详细here

我的问题是:在机器启动时让FastCGI进程自动启动的正确方法是什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

我建议在这种情况下使用wsgi,因为wsgi进程是由nginx触发的,而它是一个“独立”进程。一个典型的nginx和wsgi配置:

myproject.wsgi:

#!/usr/bin/python2.7

import djangorecipe.wsgi

application = djangorecipe.wsgi.main('settings', logfile='/var/log/django/myproject.wsgi.log')

myproject.nginx.conf:

server {
    listen       80;
    server_name  myproject.com;

    # static resources
    location ^~ /static/ {
        alias   /var/www/myproject/static/;
        expires 31d;
    }

    wsgi_var  REQUEST_METHOD      $request_method;
    wsgi_var  QUERY_STRING        $query_string;
    wsgi_var  CONTENT_TYPE        $content_type;
    wsgi_var  CONTENT_LENGTH      $content_length;
    wsgi_var  SERVER_NAME         $server_name;
    wsgi_var  SERVER_PORT         $server_port;
    wsgi_var  SERVER_PROTOCOL     $server_protocol;

    # additional variables (not used if unavailable)
    wsgi_var  REQUEST_URI         $request_uri;
    wsgi_var  DOCUMENT_URI        $document_uri;
    wsgi_var  DOCUMENT_ROOT       $document_root;
    wsgi_var  SERVER_SOFTWARE     $nginx_version;
    wsgi_var  REMOTE_ADDR         $remote_addr;
    wsgi_var  REMOTE_PORT         $remote_port;
    wsgi_var  SERVER_ADDR         $server_addr;
    wsgi_var  REMOTE_USER         $remote_user;

    location  / {
        client_body_buffer_size 50;
        wsgi_pass /var/www/myproject/myproject.wsgi;

        wsgi_pass_authorization off;
        wsgi_script_reloading on;
        wsgi_use_main_interpreter on;
    }

    # logging
    access_log  /var/log/nginx/myproject/access.log;
    error_log   /var/log/nginx/myproject/error.log;
}