瓶uwsgi nginx应用返回404 [英] bottle uwsgi nginx app returns 404

查看:387
本文介绍了瓶uwsgi nginx应用返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我已经四处走动了,不知道该怎么办:也许有人可以帮忙。
我正在尝试通过uwsgi和nginx运行瓶子应用程序。如果我用这样的瓶子服务器运行它,它将很好地工作。
python app.py
,然后将浏览器指向主机名:8080
,但是当通过nginx / uwsgi运行时,请转到:
主机名/ apps / app1
我在应用程序中收到404错误处理程序,该应用程序报告404错误。因此它正在运行该应用程序:它似乎与

OK, I've gone around and around on this and don't know what else to do: maybe someone can help. I'm trying to run a bottle app via uwsgi and nginx. It works fine if I run it with the bottle server, like this; python app.py and then point a browser to hostname:8080 but when run via nginx/uwsgi, and go to: hostname/apps/app1 I get the 404 error handler WITHIN THE APP, which reports a 404 error. So it's running the app: it just doesn't seem to match any of the

import bottle
import os

bottle.debug(True)

app = bottle.Bottle()

@app.route('/')
def default():
  return 'app1 (bottle): I am here. '

@app.route('/hello')
@app.route('/hello/')
@app.route('/hello/<name>')
def greet(name='Stranger'):
  return 'Hello, %s, how are you?' % name

@app.route('/show')
@app.route('/show/<input>')
def show(input=''):
  return 'You entered: %s' % input

@app.error(404)
def error404(error):
   return '<strong>app1: 404 error returned:</strong> %s' %error

if __name__ == '__main__':
    port = int(os.environ.get('PORT', 8080))



app.run(host ='0.0.0.0',port = port,debug = True)



这是我的uwsgi ini文件:



app.run(host='0.0.0.0', port=port, debug=True)

Here's my uwsgi ini file:

[uwsgi]
socket = /run/uwsgi/app/app1/socket
chmod-socket = 777 
chdir = /mnt/wd/www/dev/apps/app1/
file = app.py
callable = app
master = true
uid = www-data



gid = www-data



,这是Nginx站点文件的相关部分:



gid = www-data

and here is the relevant part of the nginx site file:

    location /apps {
   #    try_files @uri @uwsgi;
    }

    location /apps/app1 {
      include uwsgi_params;
      access_log /var/log/nginx/app1-access.log;
      error_log /var/log/nginx/app1-error.log;
      uwsgi_pass unix:/run/uwsgi/app/app1/socket;



}



那么:你能做什么?告诉我?感谢您的任何帮助,您可以提供。甚至有人告诉我应用程序认为它会获得
作为URL的帮助。

}

So: what can you tell me? Thanks for any help you can provide. Even something to tell me what the app thinks it's getting as the url would be helpful.

推荐答案

您已配置nginx在/ apps / app1上进行回答,因此从瓶子的角度来看,您的请求是/ apps / app1 / hello ...而不是/ hello

You have configured nginx to answer on /apps/app1, so for the bottle point of view your requests are /apps/app1/hello... instead of /hello

没有头脑的解决方案:

mount = /apps/app1=app.py
manage-script-name = true

并删除uwsgi.ini中的'file'指令

and remove the 'file' directive in uwsgi.ini

如果您想了解WSGI为什么以这种方式工作,可以检查如何管理SCRIPT_NAME和PATH_INFO

If you want to understand why WSGI works in this way, you can check how SCRIPT_NAME and PATH_INFO are managed

这篇关于瓶uwsgi nginx应用返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆