簡體   English   中英

uWSGI ini文件內的http和socket有什么區別?

[英]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文件中使用httpsocket有什么不同,我應該分別在什么時候使用它們?

擴展 Ranjeet 所說的內容,您需要確保一切都使用兼容的協議進行通信。 Nginx 的uwsgi_pass選項告訴它使用“特殊”的 uwsgi 協議。 雖然 uWSGI 的socket選項被記錄為使用其“默認協議”,這似乎實際上意味着它使用相同的“特殊”uwsgi 協議,但您可以使用uwsgi-socket選項更明確。

翻翻uwsgi是在代碼uwsgi.csocket.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM