librelist archives

« back to archive

virtually hosting flask apps with nginx

virtually hosting flask apps with nginx

From:
bruce bushby
Date:
2010-12-15 @ 09:46
Hi

Has anybody got a nginx virtual hosting config example where nginx listens
on port 80 and forwards requests to backend flask apps running on
localhost:<higher_ports> ?

Thanks

Re: [flask] virtually hosting flask apps with nginx

From:
LiChao
Date:
2010-12-15 @ 10:11
I'm using this one.

server {
    server_name asdf.com;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_set_header Host $proxy_host;
        proxy_set_header  X-Real-IP  $remote_addr;
    }
}

On Wed, Dec 15, 2010 at 5:46 PM, bruce bushby <bruce.bushby@gmail.com>wrote:

> Hi
>
> Has anybody got a nginx virtual hosting config example where nginx listens
> on port 80 and forwards requests to backend flask apps running on
> localhost:<higher_ports> ?
>
> Thanks
>

Re: [flask] virtually hosting flask apps with nginx

From:
bruce bushby
Date:
2010-12-15 @ 10:18
Thanks LiChao!!!! much appreciated.....that looks a lot more simple, will
give it a try now.


On Wed, Dec 15, 2010 at 10:11 AM, LiChao <sockpuppet.lea@gmail.com> wrote:

> I'm using this one.
>
> server {
>     server_name asdf.com;
>
>     location / {
>         proxy_pass http://127.0.0.1:5000;
>         proxy_set_header Host $proxy_host;
>         proxy_set_header  X-Real-IP  $remote_addr;
>
>     }
> }
>
> On Wed, Dec 15, 2010 at 5:46 PM, bruce bushby <bruce.bushby@gmail.com>wrote:
>
>> Hi
>>
>> Has anybody got a nginx virtual hosting config example where nginx listens
>> on port 80 and forwards requests to backend flask apps running on
>> localhost:<higher_ports> ?
>>
>> Thanks
>>
>
>

Re: [flask] virtually hosting flask apps with nginx

From:
Wael Orabi
Date:
2010-12-15 @ 09:51
try this

http://www.westphahl.net/blog/2010/4/8/running-django-nginx-and-uwsgi/

it's about setting up nginx with uwsgi for django, but it came in handy for
me

--w43L


On Wed, Dec 15, 2010 at 11:46 AM, bruce bushby <bruce.bushby@gmail.com>wrote:

> Hi
>
> Has anybody got a nginx virtual hosting config example where nginx listens
> on port 80 and forwards requests to backend flask apps running on
> localhost:<higher_ports> ?
>
>  Thanks
>

Re: [flask] virtually hosting flask apps with nginx

From:
bruce bushby
Date:
2010-12-15 @ 10:16
Thanks Wael!!  I was being lazy....looking for copy and paste :)


I think I've got it going by following:
http://rubypond.com/blog/setting-up-nginx-ssl-and-virtual-hosts
Just need to look into separating log files etc.

 My flask app is starterd from "runserver.py" (uses gevent):
#!/usr/bin/env python

import os
import sys
from gevent import wsgi

from veritrack import create_app

if __name__ == "__main__":
    wsgi.WSGIServer(('127.0.0.1', 30000), create_app()).serve_forever()

[root@core veritrack]#

I'll post what I did just in case it helps others as lazy as me.

I use Fedora, so I went into /etc/nginx/conf.d
copied virtual.conf to veritrack.co.uk.conf and added the following:

#
server {
      listen 80;
      server_name  www.veritrack.co.uk veritrack.co.uk;
      root   /var/www/apps/veritrack;

      # Set the max size for file uploads to 50Mb
      client_max_body_size 50M;

      # this rewrites all the requests to the maintenance.html
      # page if it exists in the doc root. This is for capistrano's
      # disable web task
      if (-f $document_root/maintenance.html) {
        rewrite  ^(.*)$  /maintenance.html last;
        break;
      }

      location / {
        # needed to forward user's IP address to rails
        proxy_set_header  X-Real-IP  $remote_addr;

        # needed for HTTPS
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_max_temp_file_size 0;

        # If the file exists as a static file serve it directly without
        # running all the other rewrite tests on it
        if (-f $request_filename) {
          break;
        }

        # check for index.html for directory index
        # if its there on the filesystem then rewite
        # the url to add /index.html to the end of it
        # and then break to send it to the next config rules.
        if (-f $request_filename/index.html) {
          rewrite (.*) $1/index.html break;
        }

        # this is the meat of the rails page caching config
        # it adds .html to the end of the url and then checks
        # the filesystem for that file. If it exists, then we
        # rewite the url to have explicit .html on the end
        # and then send it on its way to the next config rule.
        # if there is no file on the fs then it sets all the
        # necessary headers and proxies to our upstream mongrels
        if (-f $request_filename.html) {
          rewrite (.*) $1.html break;
        }

        if (!-f $request_filename) {
          proxy_pass http://veritrack;
          break;
        }
      }

        if (-f $request_filename) {
                break;
        }
        if (-f $request_filename/index.html) {
                rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename.html) {
                rewrite (.*) $1.html break;
        }

 }

upstream veritrack {
      server 127.0.0.1:30000;
}





On Wed, Dec 15, 2010 at 9:51 AM, Wael Orabi <wael3rabi@gmail.com> wrote:

> try this
>
> http://www.westphahl.net/blog/2010/4/8/running-django-nginx-and-uwsgi/
>
> it's about setting up nginx with uwsgi for django, but it came in handy for
> me
>
> --w43L
>
>
>
> On Wed, Dec 15, 2010 at 11:46 AM, bruce bushby <bruce.bushby@gmail.com>wrote:
>
>> Hi
>>
>> Has anybody got a nginx virtual hosting config example where nginx listens
>> on port 80 and forwards requests to backend flask apps running on
>> localhost:<higher_ports> ?
>>
>>  Thanks
>>
>
>