django - nginx不能应用mysite_nginx.conf中的配置,始终以默认配置启动
仅有的幸福
仅有的幸福 2017-05-16 17:25:22
0
7
513

[补充]关于uwsgi_params:
官网上面是这么说的:

Configure nginx for your site

You will need the uwsgi_params file, which is available in the nginx directory of the uWSGI distribution, or from https://github.com/nginx/nginx/blob/master/conf/uwsgi_params
Copy it into your project directory. In a moment we will tell nginx to refer to it.

[原文]
按照这个文档http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html部署uwsgi+nginx+django的时候,uwsgi和django或纯python配合都能出正确结果,安装了nginx之后也能在浏览器刷新看到Welcome to nginx!

然后我把nginx配置文件建立在django项目文件夹下面了:

# mysite_nginx.conf

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

# configuration of the server
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name 192.168.33.10; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /home/vagrant/mysite/mysite/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/vagrant/mysite/mysite/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/vagrant/mysite/mysite/uwsgi_params; # the uwsgi_params file you installed
    }
}

但无论是试图直接用test.py输出hello world,还是启动django服务器,都仍然只能看到Welcome to nginx!,服务器ip后面带上路径也是只有这个。

直接用test.py的时候输出如下:

$ uwsgi --socket :8001 --wsgi-file test.py *** Starting uWSGI 2.0.9 (64bit) on [Mon Feb  2 15:54:01 2015] ***
compiled with version: 4.6.3 on 02 February 2015 09:51:05
os: Linux-3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012
nodename: precise64
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /home/vagrant/mysite/mysite
detected binary path: /home/vagrant/mysite/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 2782
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :8001 fd 3
Python version: 2.7.3 (default, Dec 18 2014, 19:25:50)  [GCC 4.6.3]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1579b10
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72768 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1579b10 pid: 1655 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 1655, cores: 1)
仅有的幸福
仅有的幸福

全部回复(7)
習慣沉默

问题解决了。其实是因为/etc/nginx/sites-enabled/下面有两个配置文件:default和我自己配置的mysite_nginx.conf,nginx默认使用了default。删掉default就对了。

小葫芦

配置文件没有起作用,检查是否正确读取了 nginx的配置文件,先用个最简单的demo测试是否配置文件按是否生效

小葫芦

Nginx 配置的是8000端口,你需要访问nginx 的8000端口,

你的nginx django配置的是

 upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

所以启动django应该以8001端口为基准。

uwsgi_params 是在nginx里面。配置路径错误。 uwsgi_params 在 /etc/nginx/uwsgi_params
.

phpcn_u1582

接口冲突了,首先每个服务只监听1个接口,按照配置文件的理解应该是,nginx:8000 django:8001
在这种情况下执行python manage.py runserver localhost:8000 没有报错,说明nginx配置文件没有起作用。可能使用的还是默认的80端口启动的,请检查接口列表,linux命令为:
netstat -natp | grep nginx
如过想使用自定义的配置文件启动,请nginx -h查看具体命令 大概是-p 或者-c.
在正确配置启动nginx情况下,启动django也应该是使用python manage.py runserver localhost:8001 保证与配置文件设计相符

小葫芦

你访问的时候带上端口号了吗? http://192.168.33.10:8000

巴扎黑

确认下配置文件指向是否正确,例如

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Ty80

首先,记得带端口号。

其次,报错说明你配置错了。看错误日志吧。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板