【问题标题】:What is the differene between sockets & proxy passing between nginx and uwsgi?nginx和uwsgi之间的套接字和代理传递有什么区别?
【发布时间】:2018-09-08 13:55:56
【问题描述】:

我有一个使用flask、uwsgi 和nginx 设置的简单项目。后端仅充当服务 json 的 API,所有渲染都发生在客户端。

我一般是这样配置Nginx的:

我的设置(通过简单的代理传递):

server{
    listen 80;

    location / {
        default_type "text/html";
        alias /home/user/Project/frontend/;
    }

    location /api/ {
        proxy_pass http://0.0.0.0:8000/;
        proxy_http_version 1.1;
        proxy_pass_request_headers on;
        proxy_set_header Connection "keep-alive";

    }
}

我想象的是以这种方式运作的:

User -------> Nginx (frontend) ---(proxy pass via Nginx)---> Uwsgi (backend)

但是,最近我遇到了一个使用套接字的设置
替代设置(使用 unix 套接字):

server{
    listen 80;

    location / {
        default_type "text/html";
        alias /home/mahmoud/Documents/Projects/Research/Countries/frontend/;
    }

    location /api/ {
        include uwsgi_params;
        uwsgi_pass unix:/home/user/Project/backend/app.sock;
    }
}

引用的 uwsgi_params 文件位于 here

所以我的问题是:
使用第二种方法的优点/缺点是什么?是性能问题吗?如果是,为什么它的执行速度更快/更慢,还有其他方面吗?

【问题讨论】:

  • 我相信 uwsgi 更快(但不是很多)主要是因为在 uwsgi 中,二进制长度字节是已知的。所以正如你所看到的,改进很小。但是 uwsgi 协议已经存在,所以可以使用它。

标签: javascript html nginx


【解决方案1】:

使用 unix 套接字,您的 FastCgi 将应用程序将是安全的。您可以在套接字上应用权限,它将无法远程访问。

【讨论】:

    猜你喜欢
    • 2017-10-04
    • 2013-11-03
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 2013-09-05
    • 2018-05-09
    相关资源
    最近更新 更多