在ec2上设置Python uwsgi

时间:2015-03-03 11:40:58

标签: python linux ubuntu amazon-ec2

我正在尝试按http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html上的教程。按照我的指示:

(env1)ubuntu@ip-172-31-**-**:~/tproxy/tp$ uwsgi --http :8000 --wsgi-file test.py
*** Starting uWSGI 2.0.9 (64bit) on [Tue Mar  3 11:25:12 2015] ***
compiled with version: 4.8.2 on 03 March 2015 02:58:28
os: Linux-3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014
nodename: ip-172-31-**-**
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu/tproxy/tp
detected binary path: /home/ubuntu/.virtualenvs/env1/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 7862
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 http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 11221)
uwsgi socket 0 bound to TCP address 127.0.0.1:55522 (port auto-assigned) fd 3
Python version: 3.4.0 (default, Apr 11 2014, 13:08:40)  [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x786830
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
failed to open python file test.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 11220, cores: 1)

由于我在ec2 ubuntu实例上,我尝试在端口8000打开公共和私有ips,例如http://172.31。* :8000 /,但请求超时。我做错了什么?

编辑:我尝试进行您建议的更改。这是输出:

(env1)ubuntu@ip-172-31-28-196:~$ ls
host_type.py  requirements.txt  test.py  tproxy
(env1)ubuntu@ip-172-31-28-196:~$ sudo chmod 666 test.py
(env1)ubuntu@ip-172-31-28-196:~$ uwsgi --http :8000 --wsgi-file test.py
*** Starting uWSGI 2.0.9 (64bit) on [Tue Mar  3 14:45:58 2015] ***
compiled with version: 4.8.2 on 03 March 2015 02:58:28
os: Linux-3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014
nodename: ip-172-31-28-196
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu
detected binary path: /home/ubuntu/.virtualenvs/env1/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 7862
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)
probably another instance of uWSGI is running on the same address (:8000).
bind(): Address already in use [core/socket.c line 764]
(env1)ubuntu@ip-172-31-28-196:~$ ls -la
total 60
drwxr-xr-x 7 ubuntu ubuntu 4096 Mar  3 03:03 .
drwxr-xr-x 3 root   root   4096 Feb 20 22:20 ..
-rw------- 1 ubuntu ubuntu 1554 Mar  3 11:35 .bash_history
-rw-r--r-- 1 ubuntu ubuntu  220 Apr  9  2014 .bash_logout
-rw------- 1 ubuntu ubuntu 3751 Feb 27 19:49 .bashrc
drwx------ 3 ubuntu ubuntu 4096 Feb 27 21:08 .cache
-rw-rw-r-- 1 ubuntu ubuntu    0 Feb 23 17:15 host_type.py
drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 25 18:02 .pip
-rw-r--r-- 1 ubuntu ubuntu  675 Apr  9  2014 .profile
-rw-rw-r-- 1 ubuntu ubuntu   73 Mar  2 02:35 requirements.txt
drwx------ 2 ubuntu ubuntu 4096 Feb 20 22:20 .ssh
-rw-rw-rw- 1 root   root    136 Mar  3 03:02 test.py
drwxrwxr-x 3 ubuntu ubuntu 4096 Mar  2 18:33 tproxy
-rw------- 1 ubuntu ubuntu 4119 Feb 27 19:51 .viminfo
drwxrwxr-x 3 ubuntu ubuntu 4096 Feb 28 02:17 .virtualenvs
(env1)ubuntu@ip-172-31-28-196:~$

1 个答案:

答案 0 :(得分:1)

找不到test.py.确保它具有该文件的权限。你用sudo制作了virtuslenv吗?如果是这样,请执行chmod并将文件夹权限更改为nginx和uwsgi可以访问的内容。或者它可能是我们错误的test.py文件的路径,仔细检查。