[英]What are the differences between http and socket inside of ini file in uWSGI?
我正在学习 nginx 和 uwsgi 来部署我的 Django Web 应用程序。 在学习它们时,我对“socket”和“http”感到困惑。
.ini
。当我只使用 uwsgi ... http=127.0.0.1:8001 ...
当我使用 uwsgi 和 nginx 并且我想让客户端通过 nginx 连接到我的服务器时 ... socket=127.0.0.1:8001 ...
当我只使用 uwsgi 来运行我的服务器时,我想我应该在.ini
文件http=127.0.0.1:8001
使用“http”而不是“socket”,因为如果我使用“socket”它会在客户端连接到我的服务器时发出错误, 像这样。 invalid request block size: 21573 (max 4096)...skip
但是,当我将 nginx 与 uwsgi 一起使用时,我应该使用socket
而不是http
。 如果我使用http
,我猜服务器会发出超时错误。
这是我在 /etc/nginx/sites-available/blog.conf 中工作的代码
upstream blog{
server 127.0.0.1:8001;
}
server {
listen 80;
server_name 127.0.0.1;
charset utf-8;
client_max_body_size 75M; # adjust to taste
location /static {
alias /django_static/djProject;
}
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass blog;
}
}
在项目目录中,app.ini
[uwsgi]
plugins=python3
chdir={myProject location}
module=djProject.wsgi:application
# Settings module, relative to the chdir path
env='DJANGO_SETTINGS_MODULE=djProject.settings'
# Python virtual env path
home=/home/su/uwsgi/uwsgi-tutorial
# File used for uwsgi to send signals and start/stop
socket=127.0.0.1:8001
#http=127.0.0.1:8001
master=True
processes=4
harakiri=20
max-requests=5
vacuum=True
enable-threads=true
static-map = /static=/django_static/djProject
在.ini
文件中使用http
和socket
有什么不同,我应该分别在什么时候使用它们?
扩展 Ranjeet 所说的内容,您需要确保一切都使用兼容的协议进行通信。 Nginx 的uwsgi_pass
选项告诉它使用“特殊”的 uwsgi 协议。 虽然 uWSGI 的socket
选项被记录为使用其“默认协议”,这似乎实际上意味着它使用相同的“特殊”uwsgi 协议,但您可以使用uwsgi-socket
选项更明确。
翻翻uwsgi是在代码uwsgi.c和socket.c中这是很明显的是uwsgi-socket
只是一个别名socket
。 如果文档也这么说就好了!
如果您使用http
选项配置 uWSGI,您会告诉它使用 http 协议,这不会做任何有用的事情,因为 NGINX 正在尝试使用上述特殊的 uwsgi 协议与它对话。 请注意,您还可以将 NGINX 配置为使用 HTTP 与 uWSGI 对话,但这会丢失信息,因为您基本上是在进行代理,并且 NGINX 将不得不重写标头以表示它正在代理,并且最终会做更多的工作
另请参阅https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html ,其中有很多关于让事情相互联系的内容,您可以忽略 Django 位!
不要与这两个不同的项目(uwsgi 和 http)混淆。
正如您已经提到的,您正在使用 uwsgi 和 nginx 服务器部署 python 应用程序。
在进一步之前,查看客户端对服务器(nginx)的请求
浏览器 <-> nginx <-> 套接字 <-> uwsgi <-> python 应用程序。
Nginx 负责提供 html、javascript 和 css 文件。
Nginx 无法直接与 python 应用程序通信。 因为python应用程序通过Web服务器发布应用程序的标准方式是WSGI。 这就是为什么我们需要一个 uwsgi 服务器。 这基本上与python应用程序通信并处理来自/到Web服务器nginx的请求和响应。
并且 Web 服务器/HTTP 服务器通过套接字连接与 uwsgi 服务器通信。
但是,当我将 nginx 与 uwsgi 一起使用时,我应该使用 socket 而不是 http。 如果我使用 http,我猜服务器会发出超时错误。
是的,你说的没错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.