在gunicorn下运行的Flask应用程序出现404错误 - 我的nginx配置是否正确?

时间:2015-04-22 10:53:43

标签: nginx flask gunicorn

我试图在Ubuntu服务器上使用Gunicorn运行几个Flask应用程序(使用nginx)。其中一个正在工作,但我尝试添加的新应用程序在我尝试击中它时会响应。

这是我的gunicorn配置(由supervisor运行):

NAME="leaving_app" # Name of the application
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd /var/www/mattandrews/leaving/
source /var/www/mattandrews/leaving/ve/bin/activate

exec /var/www/mattandrews/leaving/ve/bin/gunicorn leaving:app  \
  --bind my.server.ip.here:8003
  --name $NAME \
  --workers $NUM_WORKERS \
  --log-level=debug \

如果我直接转到my.server.ip.here:8003我可以看到它正常运行。这是nginx配置:

server {
    listen          80;
    server_name     mydomain.com;
    root            /var/www/mattandrews;
    index           index.php index.html index.htm;

    location /leaving {
        proxy_pass http://my.server.ip.here:8003;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header X-Script-Name /leaving;
    }

    location = / {
        proxy_pass http://my.server.ip.here:8002;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }
}

在端口8002上运行的应用程序在根目录上运行(并且可以正常运行),但是当我尝试点击mydomain.com/leaving时,我得到了404。

查看nginx错误日志,我看到以下消息:

2015/04/21 18:32:25 [debug] 25809#0: *749454 http upstream check client, write event:1, "/leaving/"
2015/04/21 18:32:25 [debug] 25809#0: *749454 http upstream recv(): -1 (11: Resource temporarily unavailable)
2015/04/21 18:32:25 [debug] 25809#0: *749454 post event 097AA498
2015/04/21 18:32:25 [debug] 25809#0: *749454 post event 097CD160
2015/04/21 18:32:25 [debug] 25809#0: *749454 delete posted event 097CD160
2015/04/21 18:32:25 [debug] 25809#0: *749454 http upstream request: "/leaving/?"
2015/04/21 18:32:25 [debug] 25809#0: *749454 http upstream dummy handler
2015/04/21 18:32:25 [debug] 25809#0: *749454 delete posted event 097AA498
2015/04/21 18:32:25 [debug] 25809#0: *749454 http upstream request: "/leaving/?"
2015/04/21 18:32:25 [debug] 25809#0: *749454 http upstream process header
2015/04/21 18:32:25 [debug] 25809#0: *749454 malloc: 097F6CA0:131072
2015/04/21 18:32:25 [debug] 25809#0: *749454 recv: fd:9 153 of 131072
2015/04/21 18:32:25 [debug] 25809#0: *749454 http proxy status 404 "404 NOT FOUND"
2015/04/21 18:32:25 [debug] 25809#0: *749454 http proxy header: "Server: gunicorn/19.3.0"
2015/04/21 18:32:25 [debug] 25809#0: *749454 http proxy header: "Date: Tue, 21 Apr 2015 22:32:25 GMT"
2015/04/21 18:32:25 [debug] 25809#0: *749454 http proxy header: "Connection: close"
2015/04/21 18:32:25 [debug] 25809#0: *749454 http proxy header: "Content-Type: text/html"
2015/04/21 18:32:25 [debug] 25809#0: *749454 http proxy header: "Content-Length: 233"
2015/04/21 18:32:25 [debug] 25809#0: *749454 http proxy header done
2015/04/21 18:32:25 [debug] 25809#0: *749454 xslt filter header
2015/04/21 18:32:25 [debug] 25809#0: *749454 HTTP/1.1 404 NOT FOUND

一些谷歌搜索表明11: Resource temporarily unavailable与某些gunicorn issue有关,但没有任何对我有用。

有没有人有关于接下来要尝试什么的任何指示?

编辑:这是Flask应用程序的相关部分:

@app.route('/')
def home():
    return render_template('index.html')

0 个答案:

没有答案