NginX为另一个实例上运行的uWSGI提供服务

时间:2017-11-07 03:40:00

标签: nginx amazon-ec2 uwsgi

实例1:我有uWSGI& Nginx在api.test.com可以访问的实例上运行。

实例2:我还有另一个运行uWSGI和Nginx的AWS实例,可以通过ec2-x-x-x-x.com访问。

我试图通过使用第一个网址api.text.com来访问在我的第二个实例中运行的uWSGi,而不更改任何与域名相关的内容。

初始实例1:

server {
    listen 80;
    server_name www.api.test.com api.test.com;

    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:5000;
    }
}

初始实例2:

server {
    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:5000;
    }
}

此时,Nginx和uWSGI在两个实例上都运行良好。

不用修改实例2.最终实例1:

server {
    listen 80;
    server_name www.api.test.com api.test.com;

    location / {
        include uwsgi_params;
        uwsgi_pass ec2-x-x-x-x.com:80;
    }
}

在实例1中引发错误Nginx记录上游过早关闭的连接。阅读类似的问题,但无法弄清楚!

1 个答案:

答案 0 :(得分:0)

自己解决了!

在修改后的实例1中放置uwsgi_pass ec2-x-x-x-x.com:5000;而不是uwsgi_pass ec2-x-x-x-x.com:80;解决了这个问题。我把:80因为我认为请求必须在实例2中通过Nginx但不是必需的。

此外,实例2中的Nginx在从实例1访问实例2的uwsgi时不需要运行。如果要从ec2-x-x-x-x.com等浏览器访问它,必须拥有Nginx。