nginx+uwsgi+django(mac)

参考:

http://www.cnblogs.com/fnng/p/5268633.html

https://www.cnblogs.com/if-then/p/7259865.html

但是都有些看不懂的地方,所以总结一下

 

总流程就是:

nginx通过/usr/local/etc/nginx/nginx.conf与uwsgi建立联系,uwsgi通过*.ini的配置文件与django建立联系

 

1、安装nginx  网上有很多例子
2、安装uwsgi 

3、建立nginx与uwsgi联系:vi /usr/local/etc/nginx/nginx.conf

    server {
        listen       8090;#nginx监听的端口号
        server_name  localhost;#nginx监听的ip

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            include  uwsgi_params;
            uwsgi_pass  127.0.0.1:8000;#nginx通过该ip+port与uwsgi交互

            index  index.html index.htm;

4、安装django

5、创建django工程

django-admin.py startproject HelloWorld

[~/work/go/src/github.com/django/HelloWorld]$tree
.
|-- HelloWorld
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- settings.py
|   |-- settings.pyc
|   |-- urls.py
|   |-- urls.pyc
|   |-- wsgi.py
|   `-- wsgi.pyc
|-- db.sqlite3
|-- manage.py
|-- myweb_uwsgi.ini

 

6、建立uwsgi与django的联系

在~/work/go/src/github.com/django/HelloWorld添加配置文件myweb_uwsgi.ini

[~/work/go/src/github.com/django/HelloWorld]$cat myweb_uwsgi.ini 
# myweb_uwsgi.ini file
[uwsgi]

# Django-related settings

socket = :8000

# the base directory (full path)
chdir           = /Users/kunliang/work/go/src/github.com/django/HelloWorld

# Django s wsgi file
module          = HelloWorld.wsgi

# process-related settings
# master
master          = true

# maximum number of worker processes
processes       = 4

# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true

# pidfile for record run pid 
pidfile        =pid.uwsgi
# run process background and save log to daemonize
#daemonize    = UWSGI.log 

 

 

7、启动uwsgi

uwsgi --ini myweb_uwsgi.ini

 

8、重新启动nginx

nginx -s reload

9、访问 127.0.0.1:8090

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章