1

我正在尝试使用 Nginx + uWSGI 在 Amazon EC2 上设置 Django 应用程序。

遵循这些基本教程

https://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html http://www.yaconiello.com/blog/setting-aws-ec2-instance-nginx-django-uwsgi-and-mysql/# stash.TsdnEDM8.oK2geOwb.dpbs

Nginx 欢迎页面出现 ok,Instance is running,Loadbalancer is In Service,Route53 对 loadbalancer 的别名。但我看不到我的应用程序...

该应用程序似乎正在运行。我已经在本地进行了测试,并且可以正常工作。

我在终端上输入

uwsgi --ini myproject_uwsgi.ini

得到这个

[uWSGI] getting INI configuration from myproject_uwsgi.ini
*** Starting uWSGI 1.9.15 (64bit) on [Wed Sep 11 06:14:04 2013] ***
compiled with version: 4.7.3 on 10 September 2013 09:27:00
os: Linux-3.8.0-19-generic #29-Ubuntu SMP Wed Apr 17 18:16:28 UTC 2013
nodename: ip-10-252-80-160
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu/myproject
writing pidfile to /tmp/myproject-master.pid
detected binary path: /usr/local/bin/uwsgi
your processes number limit is 4569
your memory page size is 4096 bytes
 *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers *** 
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to UNIX address /tmp/myproject.sock fd 3
Python version: 2.7.4 (default, Apr 19 2013, 18:30:41)  [GCC 4.7.3]
Set PythonHome to /home/ubuntu/.virtualenvs/myproject
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1235b30
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 363880 bytes (355 KB) for 4 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1235b30 pid: 1500 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1500)
spawned uWSGI worker 1 (pid: 1501, cores: 1)
spawned uWSGI worker 2 (pid: 1502, cores: 1)
spawned uWSGI worker 3 (pid: 1503, cores: 1)
spawned uWSGI worker 4 (pid: 1504, cores: 1)

我尝试查看error.log,但我什么也没得到...

编辑

myproject_uwsgi.ini

[uwsgi]

# Django-related settings
chdir = /home/ubuntu/myproject
module = myproject.wsgi
home = /home/ubuntu/.virtualenvs/myproject
env = DJANGO_SETTINGS_MODULE=myproject.settings

# process-related settings
master = true
processes = 4
socket = /tmp/myproject.sock
chmod-socket = 664
harakiri = 20
vacuum = true
max-requests = 5000
pidfile = /tmp/myproject-master.pid
daemonize = /home/ubuntu/myproject/log/myproject.log

myproject_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///tmp/myproject.sock;
    # server 127.0.0.1:8001;
    }

# configuration of the server
server {
    listen 80;
    server_name myproject.com www.myproject.com;
    charset utf-8;

    root /home/ubuntu/myproject/;

    client_max_body_size 75M;

    location /media {
        alias /home/ubuntu/myproject/myproject/media;
    }

    location /static {
        alias /home/ubuntu/myproject/myproject/static;
    }

    location / {
        uwsgi_pass unix:///tmp/myproject.sock;
        include /home/ubuntu/myproject/uwsgi_params;
        }
    }

`

4

2 回答 2

1

我终于让我的应用程序工作了......首先我让它与 TCP 一起工作,在端口 8001 上测试,但静态文件收到错误 404。所以我希望至少让应用程序通过 unix 套接字工作,即使没有静态文件。 ..

我开始将 nginx.conf 和 uwsgi.ini 更改为套接字并开始收到错误 502。比昨天的错误(无法连接)好多了。

通过网络和SO搜索和阅读...发现nginx + uwsgi +django这个502错误

不能投票也不发表评论。但是感谢@zzart!

所以添加到我的 uwsgi.ini

uid = www-data
gid = www-data
chmod-socket = 777

我昨天添加了 uid (www-data)、gid(www-data) 和 chmod-socket = 664 或 644。但在 Amazon EC2 上对我不起作用。但是 777 使它可以工作,静态文件也可以工作。

现在我要喝杯啤酒,明天将更改安全组、负载均衡器和 route53。

希望它可以帮助别人。

于 2013-09-13T10:28:29.393 回答
0

Amazon EC2 中使用 FastCGI 守护程序的简单示例

    django.sh  -> https://gist.github.com/romuloigor/5707566
    nginx.conf -> https://gist.github.com/romuloigor/5707527
于 2013-09-11T14:00:13.220 回答