Unknown macro: {metadata-list}
| Name | NGINX for Pylons |
|---|---|
| Space | Pylons Cookbook |
| Section | Deployment |
| Version | 1.0 |
| Status | Draft |
| Reviewed | False |
| Author(s) | Pradeep Gowda |
Introduction
This article describes how to configure an NGINX server to proxy to a Pylons application run using the paster serve command.
location / {
include /usr/local/nginx/conf/proxy.conf;
proxy_pass http://127.0.0.1:8080;
proxy_redirect default;
}
The complete configuration is listed below. Copy this file to /etc/nginx or /usr/local/nginx/conf/ depending on your installation path.
nginx.conf
worker_processes 2;
events {
worker_connections 1024;
}
http {
include conf/mime.types;
default_type application/octet-stream;
access_log logs/mysite.access.log ;
error_log logs/mysite.error.log;
gzip on;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 75 20;
server {
listen 80;
server_name mysite.com;
#site runs on Pylons
location / {
include /usr/local/nginx/conf/proxy.conf;
proxy_pass http://127.0.0.1:8080;
proxy_redirect default;
}
#Blog runs on wordpress,
#so pass the control to apache running on port 81
location /blog{
proxy_pass http://127.0.0.1:81;
proxy_redirect default;
}
#URL Rewrite example
rewrite ^/feed/(.*)$ /blog/feed/$1 permanent;
}
}
The proxy file referred above is given below.
proxy.conf
proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k;
Comments (8)
Mar 26, 2007
Max Ischenko says:
Shouldn't this page belong to "Deployment" section of the cookbook?Shouldn't this page belong to "Deployment" section of the cookbook?
Nov 29, 2007
Jamie Becker says:
It will be faster to use FastCGI instead of proxying. Nginx just hands off the f...It will be faster to use FastCGI instead of proxying. Nginx just hands off the fastcgi connection to a FastCGI server running on port x, and then a FastCGI server (pylons) responds on that port. Check the documentation for nginx to find out how to set up FastCGI, but here's a start:
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location /
Nov 29, 2007
Jamie Becker says:
Ok, that paste didn't go so well. Trying again. In your nginx.conf, in the locat...Ok, that paste didn't go so well. Trying again. In your nginx.conf, in the location / { section,
enter some fastcgi_params (or include them in another file as shown above):
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_index index;
fastcgi_pass 127.0.0.1:9000;
Then configure your Pylons to listen for FastCGI requests instead of pure HTTP requests. Search for fastcgi in the above search box on this site.
Dec 31, 2007
Jon Rosebaugh says:
Where are your benchmarks showing it's faster? In my view, the performance benef...Where are your benchmarks showing it's faster? In my view, the performance benefits of FastCGI are small or nonexistent, and are balanced out by the configuration problems and opaqueness of FastCGI.
Feb 22, 2008
Andreas Klauer says:
include conf/mime.types; this line tries to include conf/conf/mime.types ...include conf/mime.types;
this line tries to include conf/conf/mime.types for me, so I have to 'include mime.types'. I'm using the latest development version of nginx, maybe something changed, or is it just an error in the pasted config here?
There was also a } missing at the end of the file so I took liberty to add it to the wiki page directly.
May 22, 2008
Shannon -jj Behrens says:
I figured out how to tell nginx to handle static content, but proxy everything e...I figured out how to tell nginx to handle static content, but proxy everything else:
location / {
root .../myapp/myapp/public;
if (!-e $request_filename) {
proxy_pass http://127.0.0.1:5000;
}
}
I have no clue if this is THE RIGHT THING. I just took a guess and it worked
Jul 09, 2008
Shannon -jj Behrens says:
There's a thread on the mailing list about this: http://groups.google.com/group/...There's a thread on the mailing list about this: http://groups.google.com/group/pylons-discuss/browse_thread/thread/11688a11048bc9ad/403ac76126048c09?lnk=gst&q=HTTP_X_FORWARDED_FOR#403ac76126048c09
Apr 10, 2010
Tony Landis says:
Here is how to do it using uWSGI.Here is how to do it using uWSGI.