试图设置django与nginx和gunicorn合作几天,按照digital ocean设置指南,尝试了在这个论坛中找到的众多解决方案,但没有一个对我有用。
这是我的第一篇stackoverflow帖子,如果它根据你喜欢阅读的内容而错过了格式或编写得不好,我希望能够改进。
从文件夹中启动gunicorn
/home/django/virtualenv/sio/SiO
运行命令
gunicorn --bind 0.0.0.0:8000 SiO.wsgi:application
工作正常,我已经尝试将其设置为sock-folder。但我最近的尝试是wsgi.py文件所在的/ home / django / virtualenv / sio / SiO / SiO。
在查看nginx错误日志时,我找到了
2017/05/03 13:56:34 [emerg] 29248#29248: invalid number of arguments in "proxy_pass" directive in /etc/nginx/sites-enabled/sio:12
2017/05/03 13:58:54 [crit] 29275#29275: *1 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:03:53 [crit] 29275#29275: *4 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:06:02 [crit] 29422#29422: *1 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:11:51 [crit] 29422#29422: *5 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:13:10 [crit] 29422#29422: *9 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:25:34 [crit] 29422#29422: *11 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:51:30 [crit] 712#712: *1 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 15:00:41 [crit] 954#954: *1 connect() to unix:/home/django/virtualenv/sio/SiO/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO/SiO.sock:/", host: "67.207.75.163"
2017/05/03 15:02:00 [crit] 1069#1069: *1 connect() to unix:/home/django/virtualenv/sio/SiO/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO/SiO.sock:/", host: "67.207.75.163"
我的项目中没有任何.sock文件。我尝试了this修复。
项目结构的树视图:
|-- SiO
| |-- calapp
| | |-- migrations
| | | |-- __pycache__
| | | | `-- __init__.cpython-35.pyc
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | |-- css
| | | | |-- calendar.css
| | | | |-- responsive.css
| | | | `-- sidebar.css
| | | `-- js
| | | |-- calendar.js
| | | `-- jquery-1.12.4.min.js
| | |-- templates
| | | `-- calapp
| | | |-- calendar (copy).html
| | | `-- calendar.html
| | |-- admin.py
| | |-- apps.py
| | |-- forms.py
| | |-- __init__.py
| | |-- models.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- chart
| | |-- migrations
| | | |-- __pycache__
| | | | `-- __init__.cpython-35.pyc
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | |-- css
| | | | `-- chart.css
| | | `-- js
| | | `-- chart.js
| | |-- templates
| | | `-- chart
| | | `-- ChartView.html
| | |-- admin.py
| | |-- apps.py
| | |-- __init__.py
| | |-- models.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- CoAdmin
| | |-- migrations
| | | |-- __pycache__
| | | | |-- 0001_initial.cpython-35.pyc
| | | | |-- 0002_auto_20170413_0316.cpython-35.pyc
| | | | |-- 0003_auto_20170413_1514.cpython-35.pyc
| | | | `-- __init__.cpython-35.pyc
| | | |-- 0001_initial.py
| | | |-- 0002_auto_20170413_0316.py
| | | |-- 0003_auto_20170413_1514.py
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- forms.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- serializers.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | `-- css
| | | `-- signup.css
| | |-- templates
| | | `-- CoAdmin
| | | |-- admin_delete.html
| | | |-- admin_edit.html
| | | |-- admin_overview.html
| | | |-- InnsideSignup.html
| | | |-- password.html
| | | `-- signup.html
| | |-- admin.py
| | |-- apps.py
| | |-- forms.py
| | |-- __init__.py
| | |-- models.py
| | |-- serializers.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- core
| | |-- migrations
| | | |-- __pycache__
| | | | `-- __init__.cpython-35.pyc
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- forms.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | |-- css
| | | | |-- animate.css
| | | | |-- cover.css
| | | | |-- dashboard.css
| | | | |-- network.css
| | | | `-- profile.css
| | | |-- img
| | | | |-- logo.svg
| | | | `-- SiOLogo.png
| | | `-- js
| | | `-- picture.js
| | |-- templates
| | | `-- core
| | | |-- cover.html
| | | |-- dashboard.html
| | | |-- partial_settings_menu.html
| | | |-- password.html
| | | |-- profile.html
| | | `-- settings.html
| | |-- admin.py
| | |-- apps.py
| | |-- forms.py
| | |-- __init__.py
| | |-- models.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- member
| | |-- migrations
| | | |-- __pycache__
| | | | |-- 0001_initial.cpython-35.pyc
| | | | `-- __init__.cpython-35.pyc
| | | |-- 0001_initial.py
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- forms.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- serializers.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | `-- css
| | | |-- member_overview.css
| | | `-- member_signup.css
| | |-- templates
| | | `-- member
| | | |-- asoc_signup.html
| | | |-- member_confirm_delete.html
| | | |-- member_delete.html
| | | |-- member_edit.html
| | | |-- member_overview.html
| | | `-- member_signup.html
| | |-- admin.py
| | |-- apps.py
| | |-- forms.py
| | |-- __init__.py
| | |-- models.py
| | |-- serializers.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- post
| | |-- migrations
| | | |-- __pycache__
| | | | |-- 0001_initial.cpython-35.pyc
| | | | |-- 0002_auto_20170413_1514.cpython-35.pyc
| | | | |-- 0003_remove_email_sendstatus.cpython-35.pyc
| | | | `-- __init__.cpython-35.pyc
| | | |-- 0001_initial.py
| | | |-- 0002_auto_20170413_1514.py
| | | |-- 0003_remove_email_sendstatus.py
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- mail.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | |-- css
| | | | `-- post.css
| | | `-- javascript
| | | `-- post.js
| | |-- templates
| | | `-- post
| | | `-- post.html
| | |-- admin.py
| | |-- apps.py
| | |-- __init__.py
| | |-- mail.py
| | |-- models.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- __pycache__
| | |-- __init__.cpython-35.pyc
| | |-- settings.cpython-35.pyc
| | |-- urls.cpython-35.pyc
| | `-- wsgi.cpython-35.pyc
| |-- static
| | |-- css
| | | |-- jquery.Jcrop.min.css
| | | `-- SiO.css
| | |-- img
| | | |-- sio-logo.jpg
| | | `-- user.png
| | `-- js
| | |-- date.js
| | |-- ga.js
| | |-- jquery.bullseye-1.0-min.js
| | |-- jquery.Jcrop.min.js
| | |-- jquery.selection.js
| | |-- jquery.typeahead.bundle.js
| | |-- SiO.js
| | `-- SiO.markdown.js
| |-- templates
| | |-- admin
| | | `-- chart_association.html
| | |-- 403.html
| | |-- 404.html
| | |-- 500.html
| | `-- base.html
| |-- __init__.py
| |-- settings.py
| |-- urls.py
| `-- wsgi.py
|-- staticfiles
| |-- admin
| | |-- css
| | | |-- base.css
| | | |-- changelists.css
| | | |-- dashboard.css
| | | |-- fonts.css
| | | |-- forms.css
| | | |-- login.css
| | | |-- rtl.css
| | | `-- widgets.css
| | |-- fonts
| | | |-- LICENSE.txt
| | | |-- README.txt
| | | |-- Roboto-Bold-webfont.woff
| | | |-- Roboto-Light-webfont.woff
| | | `-- Roboto-Regular-webfont.woff
| | |-- img
| | | |-- gis
| | | | |-- move_vertex_off.svg
| | | | `-- move_vertex_on.svg
| | | |-- calendar-icons.svg
| | | |-- icon-addlink.svg
| | | |-- icon-alert.svg
| | | |-- icon-calendar.svg
| | | |-- icon-changelink.svg
| | | |-- icon-clock.svg
| | | |-- icon-deletelink.svg
| | | |-- icon-no.svg
| | | |-- icon-unknown-alt.svg
| | | |-- icon-unknown.svg
| | | |-- icon-yes.svg
| | | |-- inline-delete.svg
| | | |-- LICENSE
| | | |-- README.txt
| | | |-- search.svg
| | | |-- selector-icons.svg
| | | |-- sorting-icons.svg
| | | |-- tooltag-add.svg
| | | `-- tooltag-arrowright.svg
| | `-- js
| | |-- admin
| | | |-- DateTimeShortcuts.js
| | | `-- RelatedObjectLookups.js
| | |-- vendor
| | | |-- jquery
| | | | |-- jquery.js
| | | | |-- jquery.min.js
| | | | `-- LICENSE-JQUERY.txt
| | | `-- xregexp
| | | |-- LICENSE-XREGEXP.txt
| | | |-- xregexp.js
| | | `-- xregexp.min.js
| | |-- actions.js
| | |-- actions.min.js
| | |-- calendar.js
| | |-- cancel.js
| | |-- change_form.js
| | |-- collapse.js
| | |-- collapse.min.js
| | |-- core.js
| | |-- inlines.js
| | |-- inlines.min.js
| | |-- jquery.init.js
| | |-- popup_response.js
| | |-- prepopulate_init.js
| | |-- prepopulate.js
| | |-- prepopulate.min.js
| | |-- SelectBox.js
| | |-- SelectFilter2.js
| | |-- timeparse.js
| | `-- urlify.js
| |-- css
| | |-- animate.css
| | |-- bootstrap-datetimepicker.css
| | |-- bootstrap.min.css
| | |-- calendar.css
| | |-- chart.css
| | |-- cover.css
| | |-- dashboard.css
| | |-- datetimepicker.css
| | |-- jquery.Jcrop.min.css
| | |-- member_overview.css
| | |-- member_signup.css
| | |-- network.css
| | |-- post.css
| | |-- profile.css
| | |-- responsive.css
| | |-- sidebar.css
| | |-- signup.css
| | `-- SiO.css
| |-- fonts
| | |-- glyphicons-halflings-regular.eot
| | |-- glyphicons-halflings-regular.svg
| | |-- glyphicons-halflings-regular.ttf
| | |-- glyphicons-halflings-regular.woff
| | `-- glyphicons-halflings-regular.woff2
| |-- img
| | |-- logo.svg
| | |-- sio-logo.jpg
| | |-- SiOLogo.png
| | `-- user.png
| |-- javascript
| | `-- post.js
| |-- js
| | |-- locales
| | | |-- bootstrap-datetimepicker.ar.js
| | | |-- bootstrap-datetimepicker.bg.js
| | | |-- bootstrap-datetimepicker.ca.js
| | | |-- bootstrap-datetimepicker.cs.js
| | | |-- bootstrap-datetimepicker.da.js
| | | |-- bootstrap-datetimepicker.de.js
| | | |-- bootstrap-datetimepicker.ee.js
| | | |-- bootstrap-datetimepicker.el.js
| | | |-- bootstrap-datetimepicker.es.js
| | | |-- bootstrap-datetimepicker.fi.js
| | | |-- bootstrap-datetimepicker.fr.js
| | | |-- bootstrap-datetimepicker.he.js
| | | |-- bootstrap-datetimepicker.hr.js
| | | |-- bootstrap-datetimepicker.hu.js
| | | |-- bootstrap-datetimepicker.id.js
| | | |-- bootstrap-datetimepicker.is.js
| | | |-- bootstrap-datetimepicker.it.js
| | | |-- bootstrap-datetimepicker.ja.js
| | | |-- bootstrap-datetimepicker.ko.js
| | | |-- bootstrap-datetimepicker.kr.js
| | | |-- bootstrap-datetimepicker.lt.js
| | | |-- bootstrap-datetimepicker.lv.js
| | | |-- bootstrap-datetimepicker.ms.js
| | | |-- bootstrap-datetimepicker.nb.js
| | | |-- bootstrap-datetimepicker.nl.js
| | | |-- bootstrap-datetimepicker.no.js
| | | |-- bootstrap-datetimepicker.pl.js
| | | |-- bootstrap-datetimepicker.pt-BR.js
| | | |-- bootstrap-datetimepicker.pt.js
| | | |-- bootstrap-datetimepicker.ro.js
| | | |-- bootstrap-datetimepicker.rs.js
| | | |-- bootstrap-datetimepicker.rs-latin.js
| | | |-- bootstrap-datetimepicker.ru.js
| | | |-- bootstrap-datetimepicker.sk.js
| | | |-- bootstrap-datetimepicker.sl.js
| | | |-- bootstrap-datetimepicker.sv.js
| | | |-- bootstrap-datetimepicker.sw.js
| | | |-- bootstrap-datetimepicker.th.js
| | | |-- bootstrap-datetimepicker.tr.js
| | | |-- bootstrap-datetimepicker.ua.js
| | | |-- bootstrap-datetimepicker.uk.js
| | | |-- bootstrap-datetimepicker.zh-CN.js
| | | `-- bootstrap-datetimepicker.zh-TW.js
| | |-- bootstrap-datetimepicker.js
| | |-- calendar.js
| | |-- chart.js
| | |-- date.js
| | |-- ga.js
| | |-- jquery-1.12.4.min.js
| | |-- jquery.bullseye-1.0-min.js
| | |-- jquery.Jcrop.min.js
| | |-- jquery.selection.js
| | |-- jquery.typeahead.bundle.js
| | |-- picture.js
| | |-- SiO.js
| | `-- SiO.markdown.js
| `-- rest_framework
| |-- css
| | |-- bootstrap.min.css
| | |-- bootstrap-tweaks.css
| | |-- default.css
| | `-- prettify.css
| |-- docs
| | |-- css
| | | |-- base.css
| | | |-- bootstrap.min.css
| | | |-- bootstrap-theme.min.css
| | | |-- font-awesome-4.0.3.css
| | | |-- highlight.css
| | | `-- jquery.json-view.min.css
| | |-- fonts
| | | |-- fontawesome-webfont.eot
| | | |-- fontawesome-webfont.svg
| | | |-- fontawesome-webfont.ttf
| | | |-- fontawesome-webfont.woff
| | | |-- glyphicons-halflings-regular.eot
| | | |-- glyphicons-halflings-regular.svg
| | | |-- glyphicons-halflings-regular.ttf
| | | |-- glyphicons-halflings-regular.woff
| | | `-- glyphicons-halflings-regular.woff2
| | |-- img
| | | |-- favicon.ico
| | | `-- grid.png
| | `-- js
| | |-- api.js
| | |-- base.js
| | |-- bootstrap.min.js
| | |-- highlight.pack.js
| | |-- jquery-1.10.2.min.js
| | `-- jquery.json-view.min.js
| |-- fonts
| | |-- glyphicons-halflings-regular.eot
| | |-- glyphicons-halflings-regular.svg
| | |-- glyphicons-halflings-regular.ttf
| | |-- glyphicons-halflings-regular.woff
| | `-- glyphicons-halflings-regular.woff2
| |-- img
| | |-- glyphicons-halflings.png
| | |-- glyphicons-halflings-white.png
| | `-- grid.png
| `-- js
| |-- ajax-form.js
| |-- bootstrap.min.js
| |-- coreapi-0.1.0.js
| |-- csrf.js
| |-- default.js
| |-- jquery-1.12.4.min.js
| `-- prettify-min.js
|-- manage.py
`-- requirements.txt
我的gunicorn文件位于
/home/django/virtualenv/sio/bin/gunicorn
/etc/systemd/system/gunicorn.service的内容
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=django
Group=www-data
WorkingDirectory=/home/django/virtualenv/sio/SiO
ExecStart=/home/django/virtualenv/sio/bin/gunicorn --workers 3 --bind unix:/home/django/virtualenv/sio/SiO/SiO SiO.wsgi:application
[Install]
WantedBy=multi-user.target
和我的/ etc / nginx / sites-available / sio文件
server {
listen 80;
server_name 67.207.75.163;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/django/virtualenv/sio/SiO;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/django/virtualenv/sio/SiO/SiO.sock;
}
}
当尝试仅使用django内置的网络服务器运行时,该网站可以正常运行。当尝试使用gunicorn访问时,我收到502错误。
答案 0 :(得分:0)
你错过了" .sock"在这一行:
ExecStart = / home / django / virtualenv / sio / bin / gunicorn --workers 3 - 绑定unix:/ home / django / virtualenv / sio / SiO / SiO SiO.wsgi:application
你绑定到文件夹而不是sock文件,但是你要告诉nginx寻找/home/django/virtualenv/sio/SiO/SiO.sock
所以,也许试试这个:
ExecStart = / home / django / virtualenv / sio / bin / gunicorn --workers 3 - 绑定unix:/home/django/virtualenv/sio/SiO/SiO.sock SiO.wsgi:application
编辑:顺便说一下,我是这个设置的忠实粉丝并且不能足够推荐它 - http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
答案 1 :(得分:0)
进行您建议的更改并没有解决问题,尝试在新VM中发送的指南可以解决所有问题。谢谢!这是非常好的,通常数字海洋指南是我的首选,但你已经说服我看其他地方:)。