【发布时间】:2013-09-15 01:37:53
【问题描述】:
我正在尝试使用 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/#sthash.TsdnEDM8.oK2geOwb.dpbs
Nginx 欢迎页面显示正常,实例正在运行,负载均衡器正在服务中,Route53 为负载均衡器的别名。但我看不到我的应用...
应用程序似乎正在运行。我已经在本地测试过,它可以工作。
我在终端上输入了
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;
}
}
`
【问题讨论】:
-
你能添加你的 myproject_uwsgi.ini 和 nginx 配置文件吗?另外,当你这样做时,你可以守护它,还是打开另一个终端到同一个盒子并向 localhost 发出请求?
-
@sberry 我添加了 myproject_uwsgi 和 myproject_nginx.conf。我正在尝试的其他事情......在这里对不起新手
-
我将守护进程添加到 myproject_uwsgi.ini 并输入 tail -f myproject.log 并在输入 uwsgi myproject_uwsgi.ini 时得到几乎相同的结果
-
点击页面时看到什么错误?
-
@Amit 昨天我仍然无法让应用程序工作几乎放弃...我可以看到访问日志但错误日志始终为空。在没有 LoadBalancer 和 Route53 的情况下重新开始......只有 Ec2 实例和 Securiy 组......将安全组设置为在没有亚马逊默认设置的情况下监听 80,将 22 和 8000 全部设置为 0.0.0.0 进行测试。当 manage.py 运行服务器时,我可以看到应用程序正在运行。我还在 myproject_nginx.conf 上放了一行 error_log,但它没有被创建。正在创建的套接字可以在 tmp 目录中看到。我昨天也让它与 uwsgi 一起工作,但我忘记了命令:(...这个晚上又会很长
标签: django nginx amazon-ec2 wsgi uwsgi