Nginx端口转发,使用uwsgi瓶

问题描述 投票:0回答:1

我有以下问题:使用端口调用我的服务器:8770工作正常;没有它的呼叫给出以下内容:

root@server1:~# wget http://127.0.0.1
--2018-06-20 17:14:03--  http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://127.0.0.1/17121985 [following] 
--2018-06-20 17:14:03--  http://127.0.0.1/17121985
Reusing existing connection to 127.0.0.1:80.
HTTP request sent, awaiting response... 404 Not Found
2018-06-20 17:14:03 ERROR 404: Not Found.

这基本上是说,我可以与服务器通话,但我没有得到响应发送。

有什么建议?

我的瓶子应用程序运行:

@route('/')
def init(db):
# check if user_id is set
if request.get_cookie("user_id"):
    user_id = request.get_cookie("user_id")
    redirect('/' + str(user_id))

if __name__ == "__main__":
run(app=app, host='127.0.0.1', port=8770, debug=True, quiet=True)

Nginx配置:

root@server1:~# cat /etc/nginx/conf.d/bottle.conf
upstream _bottle {
server unix:/run/uwsgi/app/bottle/socket;
} 

server {
listen [::]:80;
listen 80;
listen 8770;
server_name _;
root /var/www/bottle;

location / {
proxy_pass http://127.0.0.1:8770;
    try_files $uri @uwsgi;
}

location @uwsgi {
    proxy_pass http://127.0.0.1:8770;
    include uwsgi_params;
    uwsgi_pass _bottle;
}
}

谢谢!

webserver port uwsgi forwarding
1个回答
0
投票

很简单:只需在server_name或服务器的IP上添加dns即可。

我添加了两个,我的502 Bad Gateway问题得到了解决。

用于Nginx的bottle.conf:

upstream _bottle {
    server unix:/run/uwsgi/app/bottle/socket;
}

server {
    listen [::]:80;
    listen 80;
    server_name 139.59.212.77 my-domain.org;
    root /var/www/bottle;

    location / {
        try_files $uri @uwsgi;
        uwsgi_pass _bottle;
    }

    location @uwsgi {
        proxy_pass http://127.0.0.1:8770;
        include uwsgi_params;
        uwsgi_pass _bottle;
    }

    location /css {
        alias /var/www/bottle/css;
    }

    location /js {
        alias /var/www/bottle/js;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.