memo:setup nginx uwsgi web.py python

0\theories

client ----------- nginx ----------------- uwsgi ----------- python


1\ install 

sudo aptitude install nginx uwsgi python ... python-setuptools

easy_install web.py


2\ setting

2.1\ set nginx to connect uwsgi

sudo vi /etc/nginx/site-available/www

===================

server {
        listen   80;
        server_name localhost;
        location / {
                include uwsgi_params;
                uwsgi_pass unix:///var/run/uwsgi/app/www/socket;
        }
}

===================

sudo ln -s  /etc/nginx/site-available/www  /etc/nginx/site-enable/www


2.2\ set uwsgi to load python files

sudo vi /etc/uwsgi/apps-available/www.ini

===================

[uwsgi]
socket = /var/run/uwsgi/app/www/socket
chmod-socket = 666
limit-as = 256
processes = 6
max-request = 2000
memory-report = true
enable-threads = true
pythonpath = /home/chenee/www
chdir = /home/chenee/www/mysite.webpy
wsgi-file = /home/chenee/www/mysite.webpy/index.py

===================

sudo ln -s /etc/uwsgi/apps-available/www.ini /etc/uwsgi/apps-enable/www.ini


2,3\ set the python file for uwsgi (It's use web.py web framework)

mkdir -p /home/chenee/www/mysite.webpy

vi  /home/chenee/www/mysite.webpyindex.py

===================

#!/usr/bin/python
import web
 
urls = (
    "/", "hello",
)
app = web.application(urls, globals())
 
class hello: 
    def GET(self):
        return 'Hello,chenee world!'
 
application = app.wsgifunc()

===================

start nginx , uwsgi

sudo nginx 

sudo invoke-rc.d uwsgi restart


3\over;


when surf http://localhost/ ; nginx will connect uwsgi through socket(/var/run/uwsgi/app/www/socket);

uwsgi will load file at (wsgi-file = /home/chenee/www/mysite.webpy/index.py)


4\TODO

try Django  ---- DONE


study source code of web.py

write some demo of python web ,like blog , or some open-source projects


start to write the RG!!




+++++++++++++++++++++++++++++++++++++

Django OK

ubuntu 12.04

1\ do NOT use: sudo aptitude install django; because the version is too lower

use: sudo pip install django; instead

cd ~/www/

django-admin.py startproject mysite
cd mysite
python manage.py startapp myapp


2\ configue uWSGI:
vi ~/mysite/uwsgi.xml
=====================
    <uwsgi>
     <master>true</master>
        <socket>127.0.0.1:9090</socket>
        <pythonpath>..</pythonpath>
        <module>mysite.wsgi</module>
    </uwsgi>
=====================


uwsgi -x ~/mysite/uwsgi.xml

3\ surf http://localhost/ 
Welcome to django 




你可能感兴趣的:(memo:setup nginx uwsgi web.py python)