Python中文
首页
教程
问答
标签
搜索
登录
注册
Django gunicorn sock文件不是由wsgi创建的
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我的数字海洋服务器(Ubuntu 16.04)中有一个基本的django-rest应用程序,带有一个本地虚拟环境。 基本wsgi.py是:</p> <pre><code>import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "workout_rest.settings") # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. from django.core.wsgi import get_wsgi_application application = get_wsgi_application() # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application) </code></pre> <p>我已经循序渐进地学习了本教程: <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04" rel="noreferrer">https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04</a></p> <p>当我用这个命令测试Gunicorn为项目服务的能力时: gunicorn—绑定0.0.0.0:8000 myproject.wsgi:application 一切正常。</p> <p>所以我试着设置Gunicorn来使用systemd服务文件。 我的/etc/systemd/system/gunicorn.service文件是:</p> <pre><code>[Unit] Description=gunicorn daemon After=network.target [Service] User=ben Group=www-data WorkingDirectory=/home/ben/myproject ExecStart=/home/ben/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:/home/ben/myproject/myproject.sock myproject.wsgi:application [Install] WantedBy=multi-user.target </code></pre> <p>我的Nginx配置是:</p> <pre><code>server { listen 8000; server_name server_domain_or_IP; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /home/ben/myproject; } location / { include proxy_params; proxy_pass http://unix:/home/ben/myproject/myproject.sock; } } </code></pre> <p>我已将侦听端口从80更改为8000,因为80给了我一个err_connection_拒绝的错误。 使用此命令启动服务器后:</p> <pre><code>sudo systemctl restart nginx </code></pre> <p>当我试图运行我的网站,我得到一个502坏网关错误。 我试过这些命令(可以在教程注释中找到):</p> <pre><code>sudo systemctl daemon-reload sudo systemctl start gunicorn sudo systemctl enable gunicorn sudo systemctl restart nginx </code></pre> <p>但什么都没变。 当我使用这个命令查看Nginix日志时:</p> <pre><code>sudo tail -f /var/log/nginx/error.log </code></pre> <p>我可以看到sock文件不存在:</p> <pre><code>2016/10/07 09:00:18 [crit] 24974#24974: *1 connect() to unix:/home/ben/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: 86.197.20.27, server: 139.59.150.116, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ben/myproject/myproject.sock:/", host: "server_ip_adress:8000" </code></pre> <p>为什么不创建这个sock文件?如何配置django/gunicorn来创建此文件? 我已经在我的Django项目中的INSTALLED_应用程序中添加了gunicorn,但它没有任何改变。</p> <p><strong>编辑:</strong></p> <p>当我用<code>nginx -t</code>测试nginx配置文件时,得到一个错误:<code>open() "/run/nginx.pid" failed (13: Permission denied)</code>。 但如果我使用sudo:<code>sudo nginx -t</code>运行该命令,则测试成功。这是否意味着我必须允许“ben”用户运行Ngnix?</p> <p>关于gunicorn日志文件,我找不到读取它们的方法。它们存放在哪里?</p> <p>当我使用<code>ps aux | grep gunicorn</code>检查gunicorn是否正在运行时:</p> <pre><code>ben 26543 0.0 0.2 14512 1016 pts/0 S+ 14:52 0:00 grep --color=auto gunicorn </code></pre> <p>下面是在运行gunicorn的systemctl enable和start命令时发生的情况:</p> <pre><code>sudo systemctl enable gunicorn Synchronizing state of gunicorn.service with SysV init with /lib/systemd/systemd-sysv-install... Executing /lib/systemd/systemd-sysv-install enable gunicorn sudo systemctl start gunicorn I get no output with this command sudo systemctl is-active gunicorn active sudo systemctl status gunicorn ● gunicorn.service - gunicorn daemon Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled) Active: active (exited) since Thu 2016-10-06 15:40:29 UTC; 23h ago Oct 06 15:40:29 DevUsine systemd[1]: Started gunicorn.service. Oct 06 18:52:56 DevUsine systemd[1]: Started gunicorn.service. Oct 06 20:55:05 DevUsine systemd[1]: Started gunicorn daemon. Oct 06 20:55:17 DevUsine systemd[1]: Started gunicorn daemon. Oct 06 21:07:36 DevUsine systemd[1]: Started gunicorn daemon. Oct 06 21:16:42 DevUsine systemd[1]: Started gunicorn daemon. Oct 06 21:21:38 DevUsine systemd[1]: Started gunicorn daemon. Oct 06 21:25:28 DevUsine systemd[1]: Started gunicorn daemon. Oct 07 08:58:43 DevUsine systemd[1]: Started gunicorn daemon. Oct 07 15:01:22 DevUsine systemd[1]: Started gunicorn daemon. </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我已经给出了项目外部sock文件的路径。我只需要创建目录,这样gunicorn就可以在该目录中创建文件,正如我在.services文件中提到的那样。基本上,我确保根据.services文件中的路径存在所有目录。无需更改权限或所有权</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
我是否正确构建了这个递归神经网络
4 回答
我是否正确理解acquire和realease是如何在python库“线程化”中工作的
9 回答
我是否正确理解Keras中的批次大小?
10 回答
我是否正确理解PyTorch的加法和乘法?
3 回答
我是否正确组织了我的Django应用程序?
4 回答
我是否正确计算执行时间?如果是这样,那么并行处理将花费更长的时间。这看起来很奇怪
4 回答
我是否每次创建新项目时都必须在PyCharm中安装numpy?(安装而不是导入)
8 回答
我是否每次运行jupyter笔记本时都必须重新启动内核?
2 回答
我是否用python安装了socks模块?
1 回答
我是否真的需要知道超过一种语言,如果我想要制作网页应用程序?
9 回答
我是否缺少spaCy柠檬化中的预处理功能?
9 回答
我是否缺少给定状态下操作的检查?
4 回答
我是否能够使用函数“count()”来查找密码中大写字母的数量((Python)
7 回答
我是否能够使用用户输入作为colorama模块中的颜色?
2 回答
我是否能够创建一个能够添加新Django.contrib.auth公司没有登录到管理面板的用户?
2 回答
我是否能够将来自多个不同网站的数据合并到一个csv文件中?
9 回答
我是否能够将目录路径转换为可以输入python hdf5数据表的内容?
5 回答
我是否能够等到一个对象被销毁,直到它创建另一个对象,然后在循环中运行time.sleep()
7 回答
我是否能够通过CBV创建用户实例,而不是首先创建表单?(Django)
6 回答
我是否要使它成为递归函数?
9 回答