[英]What are the differences between http and socket inside of ini file in uWSGI?
I'm learning nginx and uwsgi to deploy my Django web app.我正在学习 nginx 和 uwsgi 来部署我的 Django Web 应用程序。 While learning them, I got confused with "socket" and "http".
在学习它们时,我对“socket”和“http”感到困惑。
.ini
like the following..ini
。 when I use only uwsgi ... http=127.0.0.1:8001 ...当我只使用 uwsgi ... http=127.0.0.1:8001 ...
when I use uwsgi and nginx and I want to make clients connect to my server through nginx ... socket=127.0.0.1:8001 ...当我使用 uwsgi 和 nginx 并且我想让客户端通过 nginx 连接到我的服务器时 ... socket=127.0.0.1:8001 ...
When I only use uwsgi to run my server, I guess I should use "http" instead of "socket" in .ini
file http=127.0.0.1:8001
because if i use "socket" it emits errors when clients connect to my server, like this.当我只使用 uwsgi 来运行我的服务器时,我想我应该在
.ini
文件http=127.0.0.1:8001
使用“http”而不是“socket”,因为如果我使用“socket”它会在客户端连接到我的服务器时发出错误, 像这样。 invalid request block size: 21573 (max 4096)...skip
However, when I use nginx with uwsgi, I should use socket
instead of http
.但是,当我将 nginx 与 uwsgi 一起使用时,我应该使用
socket
而不是http
。 If I use http
, I guess the server emitted timeout error.如果我使用
http
,我猜服务器会发出超时错误。
this is my codes that works in /etc/nginx/sites-available/blog.conf这是我在 /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;
}
}
in project directory, app.ini在项目目录中,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
How different are they to use http
and socket
in .ini
file and when should I use them respectively?在
.ini
文件中使用http
和socket
有什么不同,我应该分别在什么时候使用它们?
expanding on what Ranjeet said, you need to make sure everything is communicating using compatible protocols.扩展 Ranjeet 所说的内容,您需要确保一切都使用兼容的协议进行通信。 Nginx's
uwsgi_pass
option tells it to use a "special" uwsgi protocol. Nginx 的
uwsgi_pass
选项告诉它使用“特殊”的 uwsgi 协议。 while uWSGI'ssocket
option is documented as using its "default protocol" which seems to actually mean it uses the same "special" uwsgi protocol, but you could use the uwsgi-socket
option to be more explicit.虽然 uWSGI 的
socket
选项被记录为使用其“默认协议”,这似乎实际上意味着它使用相同的“特殊”uwsgi 协议,但您可以使用uwsgi-socket
选项更明确。
looking through uwsgi's the code in uwsgi.c and socket.c it's pretty obvious that uwsgi-socket
is just an alias for socket
.翻翻uwsgi是在代码uwsgi.c和socket.c中这是很明显的是
uwsgi-socket
只是一个别名socket
。 it'd be nice if the docs also said that!如果文档也这么说就好了!
if you configure uWSGI with the http
option you're telling it to use the http protocol, which won't do anything useful because NGINX is trying to talk to it using the above special uwsgi protocol.如果您使用
http
选项配置 uWSGI,您会告诉它使用 http 协议,这不会做任何有用的事情,因为 NGINX 正在尝试使用上述特殊的 uwsgi 协议与它对话。 note that you could also configure NGINX to talk to uWSGI using HTTP, but this would lose information as you're basically then proxying and NGINX would have to rewrite headers to say it was proxying and would basically end up doing more work请注意,您还可以将 NGINX 配置为使用 HTTP 与 uWSGI 对话,但这会丢失信息,因为您基本上是在进行代理,并且 NGINX 将不得不重写标头以表示它正在代理,并且最终会做更多的工作
see also https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html which has got lots of stuff about getting things taking to each other, you can just ignore the Django bits!另请参阅https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html ,其中有很多关于让事情相互联系的内容,您可以忽略 Django 位!
Don't confuse with these two different items (uwsgi and http).不要与这两个不同的项目(uwsgi 和 http)混淆。
As you already mentioned, you are deploying python application with uwsgi and nginx server.正如您已经提到的,您正在使用 uwsgi 和 nginx 服务器部署 python 应用程序。
Before go further, look on the client request to server (nginx)在进一步之前,查看客户端对服务器(nginx)的请求
Browser <-> nginx <-> socket <-> uwsgi <-> python application.浏览器 <-> nginx <-> 套接字 <-> uwsgi <-> python 应用程序。
Nginx is responsible for to serve html, javascript and css files. Nginx 负责提供 html、javascript 和 css 文件。
Nginx can't communicate with python application directly. Nginx 无法直接与 python 应用程序通信。 Because python application standard way to publish applications via web server is WSGI.
因为python应用程序通过Web服务器发布应用程序的标准方式是WSGI。 That's why we need a uwsgi server.
这就是为什么我们需要一个 uwsgi 服务器。 That basically communicate with python application and handle request and response from/to web server nginx.
这基本上与python应用程序通信并处理来自/到Web服务器nginx的请求和响应。
And Web server/ HTTP server communicate with uwsgi server via socket connection.并且 Web 服务器/HTTP 服务器通过套接字连接与 uwsgi 服务器通信。
However, when I use nginx with uwsgi, I should use socket instead of http.
但是,当我将 nginx 与 uwsgi 一起使用时,我应该使用 socket 而不是 http。 If I use http, I guess the server emitted timeout error.
如果我使用 http,我猜服务器会发出超时错误。
Yes your right.是的,你说的没错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.