| 58 | I've been serving up my django site via nginx for a short while now and wanted to report my setup so that others may give it a shot. My performance over the previous setup with lighttpd is a bit better. This setup uses much less cpu and memory to achieve much better throughput and response time. The simple syntax of the nginx.conf allows you to setup a cluster of backend processes quite easily to handle load. Currently this is my nginx.conf relevant to my django site. You can reference the above links for more information about additional options. |
| 59 | |
| 60 | {{{ |
| 61 | |
| 62 | upstream djangoserv { |
| 63 | server 127.0.0.1:8801; |
| 64 | } |
| 65 | |
| 66 | server { |
| 67 | listen 80; |
| 68 | root /path/to/app; |
| 69 | server_name test.local.domain; |
| 70 | access_log /path/to/logs/appname-access.log main; |
| 71 | error_log /path/to/logs/appname-error.log; |
| 72 | |
| 73 | location / { |
| 74 | # host and port to fastcgi server |
| 75 | fastcgi_pass 127.0.0.1:8801; |
| 76 | fastcgi_param PATH_INFO $fastcgi_script_name; |
| 77 | fastcgi_param REQUEST_METHOD $request_method; |
| 78 | fastcgi_param QUERY_STRING $query_string; |
| 79 | fastcgi_param SERVER_NAME $server_name; |
| 80 | fastcgi_param SERVER_PORT $server_port; |
| 81 | fastcgi_param SERVER_PROTOCOL $server_protocol; |
| 82 | fastcgi_param CONTENT_TYPE $content_type; |
| 83 | fastcgi_param CONTENT_LENGTH $content_length; |
| 84 | fastcgi_pass_header Authorization; |
| 85 | fastcgi_intercept_errors off; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | }}} |
| 90 | |
| 91 | Once you fire up nginx you will need to start your nginx fastcgi processes. I simply use: |
| 92 | |
| 93 | {{{ |
| 94 | |
| 95 | python2.4 manage.py runfcgi method=threaded host=127.0.0.1 port=8801 |
| 96 | |
| 97 | }}} |
| 98 | |