Chinaunix首页 | 论坛 | 博客
  • 博客访问: 43640
  • 博文数量: 6
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 60
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-07 12:16
文章分类
文章存档

2015年(6)

我的朋友

分类: Python/Ruby

2015-03-24 22:32:50

1,准备工作
安装虚拟环境

  1. $pip install virtualenv
  2. $virtualenv uwsgi-test
  3. $cd uwsgi-test
  4. $source bin/activate
安装Django

  1. pip install Django
  2. django-admin.py startproject mysite
  3. cd mysite
安装uwsgi

  1. pip install uwsgi
2,测试

  1. # test.py
  2. def application(env, start_response):
  3.     start_response('200 OK', [('Content-Type','text/html')])
  4.     return [b"Hello World"] # python3
  5.     #return ["Hello World"] # python2
uwsgi --http :8000 --wsgi-file test.py
可以看到hello world

3,测试django项目
uwsgi --http :8000 --module mysite.wsgi

4,配置nginx和uwsgi


  1. # mysite_nginx.conf

  2. # the upstream component nginx needs to connect to
  3. upstream django {
  4.      server unix:///path/to/your/mysite/mysite.sock; # for a file socket
  5.     #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
  6. }

  7. # configuration of the server
  8. server {
  9.     # the port your site will be served on
  10.     listen 8000;
  11.     # the domain name it will serve for
  12.     server_name .example.com; # substitute your machine's IP address or FQDN
  13.     charset utf-8;

  14.     # max upload size
  15.     client_max_body_size 75M; # adjust to taste

  16.     # Django media
  17.     location /media {
  18.         alias /path/to/your/mysite/media; # your Django project's media files - amend as required
  19.     }

  20.     location /static {
  21.         alias /path/to/your/mysite/static; # your Django project's static files - amend as required
  22.     }

  23.     # Finally, send all non-media requests to the Django server.
  24.     location / {
  25.         uwsgi_pass django;
  26.         include /path/to/your/mysite/uwsgi_params; # the uwsgi_params file you installed
  27.     }
  28. }
创建nginx配置文件软连接
sudo ln -s ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/

# mysite_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /path/to/your/project
# Django's wsgi file
module          = project.wsgi
# the virtualenv (full path)
home            = /path/to/virtualenv

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /path/to/your/project/mysite.sock
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true


增加uwsgi自启动,修改rc.local

/usr/local/bin/uwsgi --ini /path/to/your/project/mysite_uwsgi.ini  --uid www-data --gid www-data
阅读(3028) | 评论(0) | 转发(0) |
0

上一篇:django+django-ajax

下一篇:没有了

给主人留下些什么吧!~~