开发者

uwsgi + python + nginx + willy nilly file execution

I'm using uwsgi on Nginx to run some Python code.

I'd like to bind uwsgi to a directory and make it render any .py file that I call from the server in the browser. I'm t开发者_如何学Chinking like PHP, here (/index.php executes that file, /login.php executes that file).

Is this a possibility? Or am I only able to explicitly specify a single module/app/file in uwsgi?

Here is my init syntax:

/opt/uwsgi/uwsgi -s 127.0.0.1:9001 -M 4 -t 30 -A 4 -p 4 -d /var/log/uwsgi.log --pidfile /var/run/uwsgi.pid --pythonpath /srv/www

I thought that would allow /srv/www to act as the folder where any .py files are executed.

Here is my nginx config:

server {
    listen       80;
    server_name  DONT_NEED_THIS;

    access_log  /srv/www/logs/access.log;
    error_log   /srv/www/logs/error.log;

    location / {
        root  /srv/www;

        # added lines    
        include        uwsgi_params;
        uwsgi_pass     127.0.0.1:9001;

    }

As it stands, when I try to call web root (ie www.site.com/) I get a:

wsgi application not found

With the following index.py file:

import sys
import os

sys.path.append(os.path.abspath(os.path.dirname(__file__)))

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

Any ideas?

Thanks!


WSGI is not like PHP. You can't just point uwsgi to a directory with a bunch of .py files. In fact, never, ever make your python modules available in a public directory, accessible from the server. You need to hook uwsgi up to a WSGI application, preferably a framework. Read more about WSGI here. Check out bottle which is small, simple WSGI framework. It has great docs, and it's easy to get started with. There are actually tons of great web frameworks for Python though, so feel free to look around :)


You may want to read this thread:

http://lists.unbit.it/pipermail/uwsgi/2011-March/001657.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜