免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7283 | 回复: 10
打印 上一主题 下一主题

请教nginx部署Django的问题。在线等。。。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-25 15:29 |只看该作者 |倒序浏览
本帖最后由 rjxylq 于 2010-05-25 15:38 编辑

1 我开始仿照Django书上的例子。通过网页点击http://127.0.0.1:8000/可以输出Hello world
项目名字为:mysite   在他下面有views.py  urls.py也以及设置好。
views.py内容如下:
from django.http import HttpResponse
def hello(request):
    return HttpResponse("Hello world")

urls.py的内容如下:
from django.conf.urls.defaults import *
from mysite.views import hello
urlpatterns = patterns('',
('^hello/$', hello),
)
然后在mysite目录下运行Python manage.py runserver
在网页点击http://127.0.0.1:8000/ 可以出现Hello world
问题是现在我想把他部署到nginx  不用运行Python manage.py runserver 运行nginx就可以访问上面的地址。
我下载了Flup.
请问如何配置,运行相关程序,可以效果和Python manage.py runserver一样
~

论坛徽章:
0
2 [报告]
发表于 2010-05-25 15:34 |只看该作者
回复 1# rjxylq
上面Nginx的配置文件如下:
user              nginx;
worker_processes  1;

error_log         /var/log/nginx/error.log;
#error_log        /var/log/nginx/error.log  notice;
#error_log        /var/log/nginx/error.log  info;

pid               /var/run/nginx.pid;


#----------------------------------------------------------------------
# Events Module
#
#   http://wiki.codemongers.com/NginxEventsModule
#
#----------------------------------------------------------------------

events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;

    #
    # The default server
    #

    server {
        listen       80;
        #server_name  _;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            fastcgi_pass 127.0.0.1:8000;
            fastcgi_param PATH_INFO $fastcgi_script_name;

            fastcgi_param REQUEST_METHOD $request_method;

            fastcgi_param QUERY_STRING $query_string;

            fastcgi_param CONTENT_TYPE $content_type;

            fastcgi_param CONTENT_LENGTH $content_length;

            fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
            fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
            fastcgi_param  REMOTE_ADDR        $remote_addr;
            fastcgi_param  REMOTE_PORT        $remote_port;
           fastcgi_param  SERVER_ADDR        $server_addr;
            fastcgi_param  SERVER_PORT        $server_port;
            fastcgi_param  SERVER_NAME        $server_name;

#            fastcgi_param SERVER_PROTOCOL $server_protocol;

#            fastcgi_param SERVER_PORT $server_port;

#            fastcgi_param SERVER_NAME $server_name;

            fastcgi_pass_header Authorization;

            fastcgi_intercept_errors off;

           # root   /usr/share/nginx/html;
           # index  index.html index.htm;
        }

        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
}
}

论坛徽章:
0
3 [报告]
发表于 2010-05-25 15:36 |只看该作者
之后运行python manage.py runfcgi host=127.0.0.1 port=8000  启动ngnix但是不能输出Hello world

论坛徽章:
0
4 [报告]
发表于 2010-05-25 16:27 |只看该作者
python manage.py runfcgi method=threaded host=127.0.0.1 port=9000 daemonize=false minspare=30 maxspare=150 &

论坛徽章:
0
5 [报告]
发表于 2010-05-25 16:57 |只看该作者
回复 4# fzlqq


  谢谢。不过试了一下,还是不行。还有我看官网有设置
location /site_media  {
        root /path/to/media/folder;
        }

这个是用来干嘛的? 不设置不影响吗?

论坛徽章:
0
6 [报告]
发表于 2010-05-26 09:07 |只看该作者
没影响,那个是静态文件映射

论坛徽章:
0
7 [报告]
发表于 2010-05-26 09:55 |只看该作者
回复 6# fzlqq


  是阿 我觉得也是。我现在就是要看动态的。但是就是显示不出来HelloWorld.  用Django自带服务器的话 就可以。您应该配过吧。我到底哪里错了呢 ? 还是没试出来。官网也看过。如果你清楚的话希望指点下阿 谢谢。

论坛徽章:
0
8 [报告]
发表于 2010-05-26 16:33 |只看该作者
我在window上面试了下其实很简单,有python,django的环境。
先装上flup
然后下载个解压缩版的nginx,我的是0.7.65版本的。

修改nginx.conf

将原来这段随便修改下

        location / {
            root   html;
            index  index.html index.htm;
        }

=>

        location / html{
            root   html;
            index  index.html index.htm;
        }

再在这段前面加上

        location / {
            # 指定 fastcgi 的主机和端口
            fastcgi_pass 127.0.0.1:8051;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_param CONTENT_TYPE $content_type;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_param SERVER_PROTOCOL $server_protocol;
            fastcgi_param SERVER_PORT $server_port;
            fastcgi_param SERVER_NAME $server_name;
            fastcgi_pass_header Authorization;
            fastcgi_intercept_errors off;
        }


在django项目目录中运行
python .\manage.py runfcgi method=threaded host=127.0.0.1 port=8051

启动nginx.exe

打开http://localhost就可以看到我写的测试页面,rt

论坛徽章:
0
9 [报告]
发表于 2010-05-26 17:38 |只看该作者
回复 8# t6760915


    非常谢谢 已经可以了 按照自己原来的配置就可以,不知道为什么今天就可以了 还真能碰到热心的人。谢谢

论坛徽章:
0
10 [报告]
发表于 2010-05-26 17:40 |只看该作者
回复  t6760915


    非常谢谢 已经可以了 按照自己原来的配置就可以,不知道为什么今天就可以了 还真 ...
rjxylq 发表于 2010-05-26 17:38



    呵呵,不客气,我也是第一次在nginx上面配置环境的,以前我都是使用apache
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP