Previously wrote a simple operation and maintenance management system, but has always been using the developer mode to start Django, now want to use Ngxin proxy, referring to <<the Django Book>>, which provides Apache+mod_python (Mod_ wsgi| FastCGI) and so on, and I chose the way of nginx+fastcgi (the machine has nginx, and I usually use nginx also more).
There are several ways that Django starts up through fastcgi:
Run a thread server on the TCP port:
./manage.py runfcgi method=threaded host=127.0.0.1 port=3033
To run the Prefork server on a UNIX socket:
./manage.py runfcgi method=prefork Socket=/home/user/mysite.sock pidfile=django.pid
Started, but not as a background process (easier to debug):
./manage.py runfcgi Daemonize=false Socket=/tmp/mysite.sock
The Django directory structure is as follows:
[[email protected]_56_231_centos tencent]# tree tencent/tencent/├── db.sqlite3├── log│ └── all.log├── manage.py├── scripts│ ├── changetime.sh│ ├── test.sh│ └── testtime.sh├── static│ ├── css│ │ ├── bootstrap.css .... │ │ └── bootstrap-responsive.min.css│ ├── img│ │ ├── glyphicons-halflings.png│ │ └── glyphicons-halflings-white.png│ ├── jquery│ │ └── jquery-1.8.3.min.js│ └── js│ ├── bootstrap-datetimepicker.js .... ├── tencent│ ├── __init__.py│ ├── settings.py│ ├── urls.py│ └── wsgi.py└── tencentapp ├── admin.py ├── __init__.py ├── models.py ├── template │ ├── bb.html.... │ └── ee.html ├── tests.py └── views.py
Static is the directory where you place the files
The Nginx configuration file is as follows:
server {
Listen 9007;
server_name default;
Index index.html index.htm;
Location/{
Fastcgi_pass 127.0.0.1:9008; #这是是Django启动时的套接字地址, the starting mode can be referenced above
Fastcgi_param path_info $fastcgi _script_name;
Fastcgi_param Request_method $request _method;
Fastcgi_param query_string $query _string;
Fastcgi_param Content_Type $content _type;
Fastcgi_param content_length $content _length;
Fastcgi_param server_protocol $server _protocol;
Fastcgi_param server_port $server _port;
Fastcgi_param server_name $server _name;
Fastcgi_pass_header Authorization;
Fastcgi_intercept_errors off;
}
Location ~ ^/static/{
Root/data/python/tencent/tencent; #这是Django静态文件的目录
Expires 24h;
}
}
This article is from the "Smoke Free Hand" blog, please be sure to keep this source http://lidefu.blog.51cto.com/3429777/1713479
Nginx+fastcgi+django request static (CSS,JS,IMG, etc.)