nginx - nginx + uWSGI 上的 Flask 返回 404 错误,除非 linux 目录存在

标签 nginx directory flask uwsgi

这可能是一个奇怪的问题,但我对这些事情不太有经验,而且我不知道如何搜索这种错误。

我有一个配置了 nginx 和 uWSGI 的服务器。一切运行良好,我可以看到日志中没有错误。但是,当我执行以下代码时:

from flask import Flask
app = Flask(__name__)

@app.route('/test/')
def page1():
    return 'Hello World'

@app.route('/')
def index():
    return 'Index Page'

我无法查看 http://ezte.ch/test/除非/test/目录存在于 linux 中,一旦我创建该目录,一切都会正常加载。否则,我会收到传递给 uWSGI 进程的 404 错误(它确实表明它正在终端中接收请求)。

这是我的 uWSGI config.ini:

[uwsgi]
project = eztech

uid = www-data
gid = www-data
plugins = http,python

socket = /usr/share/nginx/www/eztech/uwsgi.sock



chmod-socket = 775
chown-socket = www-data:www-data
wsgi-file hello.py
callable app
processes 4
threads 2

这是我的 nginx 配置:

            server {
    listen   80; ## listen for ipv4; this line is default and implied
    listen   [::]:80 default ipv6only=on; ## listen for ipv6
    autoindex  on;
    root /usr/share/nginx/www/eztech/public_html;
    index index.html index.htm;
    # Make site accessible from http://localhost/
    server_name ezte.ch;
    location  / {
            uwsgi_pass unix:/usr/share/nginx/www/eztech/uwsgi.sock;
            include uwsgi_params;
            uwsgi_param         UWSGI_CHDIR           /usr/share/nginx/www/eztech/public_html;
            uwsgi_param         UWSGI_MODULE    hello;
            uwsgi_param         UWSGI_CALLABLE  app;
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

下面是我使用配置文件运行 uWSGI 时得到的结果:

   [uWSGI] getting INI configuration from config.ini
   open("./http_plugin.so"): No such file or directory [core/utils.c line 3347]
   !!! UNABLE to load uWSGI plugin: ./http_plugin.so: cannot open shared object file: No such    file or directory !!!
   open("./python_plugin.so"): No such file or directory [core/utils.c line 3347]
   !!! UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No       such file or directory !!!
   *** Starting uWSGI 1.9.8 (64bit) on [Sat Apr 27 06:29:18 2013] ***
   compiled with version: 4.6.3 on 27 April 2013 00:06:22
   os: Linux-3.2.0-36-virtual #57-Ubuntu SMP Tue Jan 8 22:04:49 UTC 2013
   nodename: ip-10-245-51-230
   machine: x86_64
   clock source: unix
   detected number of CPU cores: 1
   current working directory: /usr/share/nginx/www/eztech
   detected binary path: /usr/local/bin/uwsgi
   *** WARNING: you are running uWSGI without its master process manager ***
   your processes number limit is 4595
   your memory page size is 4096 bytes
   detected max file descriptor number: 1024
   lock engine: pthread robust mutexes
   uwsgi socket 0 bound to UNIX address /usr/share/nginx/www/eztech/uwsgi.sock fd 3
   setgid() to 33
   setuid() to 33
   Python version: 2.7.3 (default, Aug  1 2012, 05:25:23)  [GCC 4.6.3]
   *** Python threads support is disabled. You can enable it with --enable-threads ***
   Python main interpreter initialized at 0x2505520
   your server socket listen backlog is limited to 100 connections
   your mercy for graceful operations on workers is 60 seconds
   mapped 72688 bytes (70 KB) for 1 cores
   *** Operational MODE: single process ***
   *** no app loaded. going in full dynamic mode ***
   *** uWSGI is running in multiple interpreter mode ***
   spawned uWSGI worker 1 (and the only) (pid: 12800, cores: 1)

感谢您提供的任何帮助!

最佳答案

正如 Blender 已经说过的,上游调用的地方不应该有 try_files。

以下 nginx 配置足以托管 Flask 应用程序:

server {
    listen 80;
    server_name ezte.ch;

    location / {
        uwsgi_pass unix:/usr/share/nginx/www/eztech/uwsgi.sock;
        include uwsgi_params;
    }
}

我的 flask 配置:

<uwsgi>
    <autostart>true</autostart>
    <master/>
    <pythonpath>/var/www/apps/someapp/</pythonpath>
    <plugin>python</plugin>
    <module>someapp:app</module>
    <processes>4</processes>
</uwsgi>

所以有路径/var/www/apps/someapp/和 Flask 文件 someapp.py

关于nginx - nginx + uWSGI 上的 Flask 返回 404 错误,除非 linux 目录存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16249054/

相关文章:

Python flask 请求返回未定义的值

amazon-web-services - 应用程序负载均衡器 session cookie 的过期时间非常高

docker - 在我的 NGINX 中的 Docker 容器 + 反向代理中设置 Rundeck

c# - 将目录移动到另一个目录时是否可以访问文件?

c - 给定的文件参数是否是目录。 C

python - 缓存一个大对象并从缓存中快速读取 flask

unit-testing - 是否可以在不运行整个 Web 服务器的情况下运行(并检查)Nginx 重写规则?

php - dockerized web 应用程序中 laravel 5/php-fpm/nginx 的超慢查询时间

node.js - 如何设置nginx配置?

c - 在C中,如何到达指定目录?