Django on Nginx

来自开放百科 - 灰狐
(版本间的差异)
跳转到: 导航, 搜索
 
 
(未显示1个用户的7个中间版本)
第1行: 第1行:
 +
apt-get install python-scgi // Server-side implementation of the SCGI protocol
 +
apt-get install python-flup // Implements Python Web Server Gateway Interface (WSGI)
 
nginx.conf
 
nginx.conf
  
  upstream djangoserv {
+
  user www-data;
  server 127.0.0.1:8801;
+
}
+
  
  server {
+
  worker_processes 2;
  listen 80;
+
root /path/to/app;
+
server_name test.local.domain;
+
access_log /path/to/logs/appname-access.log main;
+
error_log /path/to/logs/appname-error.log;
+
  
  location /styles  {
+
  error_log /var/log/nginx/error_log info;
root /path/to/styles;
+
}
+
  
  location /javascripts  {
+
  events {
  root /path/to/javascripts;
+
  worker_connections  1024;
 +
use epoll;
 
  }
 
  }
  
 +
http {
 +
include /etc/nginx/mime.types;
 +
default_type application/octet-stream;
 +
 +
log_format main
 +
'$remote_addr - $remote_user [$time_local] '
 +
          '"$request" $status $bytes_sent '
 +
'"$http_referer" "$http_user_agent" '
 +
'"$gzip_ratio"';
 +
 +
client_header_timeout 10m;
 +
client_body_timeout 10m;
 +
send_timeout 10m;
 +
 +
connection_pool_size 256;
 +
client_header_buffer_size 1k;
 +
large_client_header_buffers 4 2k;
 +
request_pool_size 4k;
 +
 +
gzip on;
 +
gzip_min_length 1100;
 +
gzip_buffers 4 8k;
 +
gzip_types text/plain;
 +
 +
output_buffers 1 32k;
 +
postpone_output 1460;
 +
 +
sendfile on;
 +
tcp_nopush on;
 +
tcp_nodelay on;
 +
 +
keepalive_timeout 75 20;
 +
 +
ignore_invalid_headers on;
 +
index index.html;
 +
 +
server {
 +
listen 80;
 +
server_name localhost;
 +
# site_media - folder in uri for static files
 +
location /site_media  {
 +
root /path/to/media/folder;
 +
}
 
  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
 
  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
        access_log  off;
+
  access_log  off; # po co mi logi obrazków :)
        expires      30d;  
+
  expires      30d;  
 
  }
 
  }
 +
location / {
 +
  # host and port to fastcgi server
 +
fastcgi_pass 127.0.0.1:8080;
 +
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_pass_header Authorization;
 +
fastcgi_intercept_errors off;
 +
}
 +
access_log /var/log/nginx/localhost.access_log main;
 +
error_log /var/log/nginx/localhost.error_log;
 +
}
 +
}
  
location / {
 
                        # host and port to fastcgi server
 
                        fastcgi_pass 127.0.0.1:8801;
 
                        fastcgi_param PATH_INFO $fastcgi_script_name;
 
                        fastcgi_param REQUEST_METHOD $request_method;
 
                        fastcgi_param QUERY_STRING $query_string;
 
                        fastcgi_param SERVER_NAME $server_name;
 
                        fastcgi_param SERVER_PORT $server_port;
 
                        fastcgi_param SERVER_PROTOCOL $server_protocol;
 
                        fastcgi_param CONTENT_TYPE $content_type;
 
                        fastcgi_param CONTENT_LENGTH $content_length;
 
                        fastcgi_pass_header Authorization;
 
                        fastcgi_intercept_errors off;
 
}
 
}
 
 
start your nginx fastcgi processes
 
start your nginx fastcgi processes
  python2.5 manage.py runfcgi method=threaded host=127.0.0.1 port=8801
+
  python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings
 +
or
 +
python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings --pythonpath=/a/path/to/somewhere/
 +
http://127.0.0.1

2009年3月8日 (日) 11:39的最后版本

apt-get install python-scgi // Server-side implementation of the SCGI protocol
apt-get install python-flup // Implements Python Web Server Gateway Interface (WSGI)

nginx.conf

user  www-data;
worker_processes  2;
error_log /var/log/nginx/error_log info;
events {
	worker_connections  1024;
	use epoll;
}
http {
	include		/etc/nginx/mime.types;
	default_type	application/octet-stream;
	log_format main
		'$remote_addr - $remote_user [$time_local] '
         	'"$request" $status $bytes_sent '
		'"$http_referer" "$http_user_agent" '
		'"$gzip_ratio"';
	client_header_timeout	10m;
	client_body_timeout	10m;
	send_timeout		10m;
	connection_pool_size		256;
	client_header_buffer_size	1k;
	large_client_header_buffers	4 2k;
	request_pool_size		4k;
	gzip on;
	gzip_min_length	1100;
	gzip_buffers	4 8k;

gzip_types text/plain;

	output_buffers	1 32k;
	postpone_output	1460;
	sendfile	on;
	tcp_nopush	on;
	tcp_nodelay	on;
	keepalive_timeout	75 20;
	ignore_invalid_headers	on;

index index.html;

server { listen 80; server_name localhost; # site_media - folder in uri for static files location /site_media { root /path/to/media/folder; }

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
  access_log   off; # po co mi logi obrazków :)
  expires      30d; 
}
		location / {
 			# host and port to fastcgi server
			fastcgi_pass 127.0.0.1:8080;
			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_pass_header Authorization;
			fastcgi_intercept_errors off;
			}
		access_log	/var/log/nginx/localhost.access_log main;
		error_log	/var/log/nginx/localhost.error_log;
		}
	}

start your nginx fastcgi processes

python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings
or
python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings --pythonpath=/a/path/to/somewhere/
http://127.0.0.1
分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱