2015-03-04 3 views
2

Я пытаюсь следовать руководству по адресу http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html. У меня все работает до http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#using-unix-sockets-instead-of-ports. Я работаю с Ubuntu 14.4 например, на Amazon EC2:Настройка Unix Socket с Nginx и Django

Конфигурационный файл Nginx начинается с:

# 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) 
} 

Я смущен о синтаксисе создания сокета UNIX. Я посмотрел на несколько источниках, включая http://pymotw.com/2/socket/uds.html, Permission denied - nginx and uwsgi socket и https://serverfault.com/questions/124517/whats-the-difference-between-unix-socket-and-tcp-ip-socket

Это выглядит как все они начинаются с «///» Если я правильно понял путь только указует на корневом каталог (в моем случае) Джанго проект и путь должен заканчиваться на «.sock». Кажется ли это правильным?

редактировать: Я сделал конфигурационный файл uwsgi, но я пытаюсь запустить это с --socket переключателем вместо:

Конфигурационный файл Nginx теперь начинается с:

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

После того, что я думаю, вы говорите, я запускаю uwsgi на socket /tmp/mysite.sock.

(env1)[email protected]:~$ uwsgi --socket /tmp/mysite.sock --wsgi-file test.py --chmod-socket=664 

Когда я открываю:

http://52.10.----:8000/ 

В светлячок я вижу:

502 Bad Gateway 

Журнал ошибок для Nginx показывает:

2015/03/04 15:08:44 [crit] 18398#0: *3 connect() to unix:///home/ubuntu/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 64.56.60.130, server: 52.10.200.38, request: "GET/HTTP/1.1", upstream: "uwsgi://unix:///home/ubuntu/mysite.sock:", host: "52.10.200.38:8000" 

редактировать 2: Я закомментирована связанные с django вещи -

# mysite_uwsgi.ini file 
[uwsgi]  

# Django-related settings 
# the base directory (full path) 
#chdir   = /path/to/your/project 
# Django's wsgi file 
#module   = project.wsgi 
# the virtualenv (full path) 
#home   = /path/to/virtualenv  

# process-related settings 
# master 
master   = true 
# maximum number of worker processes 
processes  = 1 
# the socket (use the full path to be safe 
socket   = /tmp/mysite.sock 
# ... with appropriate permissions - may be needed 
    chmod-socket = 664 
# clear environment on exit 
vacuum   = true 

Я пробовал:

(env1)[email protected]:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-file test.py 

но снова получил ошибку 502.

2015/03/04 17:50:00 [crit] 18842#0: *1 connect() to unix:///tmp/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 64.56.60.130, server: 52.10.200.38, request: "GET/HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.sock:", host: "52.10.200.38:8000" 

EDIT 3:

(env1)[email protected]:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-file te 
st.py 
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini 
*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 4 18:41:43 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 !!! 
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 socket 0 bound to UNIX address /tmp/mysite.sock 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 0x205e710 
your server socket listen backlog is limited to 100 connections 
your mercy for graceful operations on workers is 60 seconds 
mapped 145520 bytes (142 KB) for 1 cores 
*** Operational MODE: single process *** 
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x205e710 pid: 18868 (default app) 
*** uWSGI is running in multiple interpreter mode *** 
spawned uWSGI master process (pid: 18868) 
spawned uWSGI worker 1 (pid: 18869, cores: 1) 

редактировать 4: - просто заметил

♥SIGINT/SIGQUIT received...killing workers... 
worker 1 buried after 1 seconds 
goodbye to uWSGI. 
VACUUM: unix socket /tmp/mysite.sock removed. 

Так каждый раз, когда я выхожу uWSGI, сокет удаляется. Может быть, мне нужно отключить параметр вакцины, чтобы сохранить настройки chmod?

Я изменил:

vacuum   = false 

но ...

(env1)[email protected]:/tmp$ sudo chmod 777 mysite.sock 
(env1)[email protected]:/tmp$ ls -la 
total 8 
drwxrwxrwt 2 root root 4096 Mar 4 19:32 . 
drwxr-xr-x 22 root root 4096 Mar 4 19:06 .. 
srwxrwxrwx 1 ubuntu ubuntu 0 Mar 4 19:32 mysite.sock 
(env1)[email protected]:/tmp$ cd /home/ubuntu/ 
(env1)[email protected]:~$ ls 
host_type.py requirements.txt test.py tproxy 
(env1)[email protected]:~$ sudo /etc/init.d/nginx restart 
    * Restarting nginx nginx 
    ...done. 
(env1)[email protected]:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-fi 
st.py 
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini 
*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 4 19:36:42 2015] *** 
..... 
spawned uWSGI worker 1 (pid: 1568, cores: 1) 
♥SIGINT/SIGQUIT received...killing workers... 
worker 1 buried after 1 seconds 
goodbye to uWSGI. 
(env1)[email protected]:~$ cd /tmp 
(env1)[email protected]:/tmp$ ls -la 
total 8 
drwxrwxrwt 2 root root 4096 Mar 4 19:36 . 
drwxr-xr-x 22 root root 4096 Mar 4 19:06 .. 
srw-rw-r-- 1 ubuntu ubuntu 0 Mar 4 19:36 mysite.sock 

так CHMOD не сохранились ..

редактировать 5:

(env1)[email protected]:/tmp$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-file 
test.py --chmod-socket=777 
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini 
*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 4 20:54:21 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: /tmp 
detected binary path: /home/ubuntu/.virtualenvs/env1/bin/uwsgi 
!!! no internal routing support, rebuild with pcre support !!! 
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 socket 0 bound to UNIX address /tmp/mysite.sock 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 0x18b4790 
your server socket listen backlog is limited to 100 connections 
your mercy for graceful operations on workers is 60 seconds 
mapped 145520 bytes (142 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 master process (pid: 1858) 
spawned uWSGI worker 1 (pid: 1859, cores: 1) 
--- no python application found, check your startup logs for errors --- 
[pid: 1859|app: -1|req: -1/1] 64.56.60.130() {36 vars in 555 bytes} [Wed Mar 4 20:54:34 2015] GET 
/=> generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0) 

Теперь получаю внутренняя ошибка сервера:

2015/03/04 19:33:26 [crit] 1531#0: *1 connect() to unix:///tmp/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 64.56.60.130, server: 52.10.200.38, request: "GET/HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.sock:", host: "52.10.200.38:8000" 

ответ

1

Изменить это сказать сервер unix:///tmp/mysite.sock;, а затем в uwsgi ини файл, который вы делаете, создать сокет Unix в /tmp/

+0

Спасибо, что посмотрели на этого человека, я изменил конфигурацию nginx, как вы предложили. что касается конфигурации uwsgi, я предполагаю, что вы говорите о http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#configuring-uwsgi-to-run-with-a-ini-file ? Если да, то где вы помещаете этот файл, я не думаю, что он говорит, где находится. – user61629

+0

Обычно я просто помещаю его в ту же папку с файлами settings.py и wsgi.py. Вы увидите, почему позже, когда вы настраиваете императора. Это не проблема, вчера вечером я настроил эту же настройку снова на amazon ec2, чтобы попробовать, и он отлично работает. :) – electrometro

+0

, пожалуйста, см. Edit .. – user61629

Смежные вопросы