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

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