2013-04-27 91 views
2

這可能是一種奇怪的問題,但我對這些東西並不是太熟悉,我不知道如何搜索這種錯誤。nginx + uWSGI上的Flask返回一個404錯誤,除非linux目錄存在

我有一臺配置了nginx和uWSGI的服務器。一切運行良好,日誌中沒有錯誤,我可以看到。但是,當我執行下面的代碼:

from flask import Flask 
app = Flask(__name__) 

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

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

我不能,除非裏面的Linux存在/測試/目錄下一次我創建目錄,一切都加載罰款查看http://ezte.ch/test/。否則,我會得到一個傳遞給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) 

感謝您提供任何幫助!

+1

我從來沒有設法得到uWSGI運行正常,所以我切換到Gunicorn,但你有沒有嘗試過的瓶文檔中的配置? http://flask.pocoo.org/docs/deploying/uwsgi/#configuring-nginx它沒有'try_files'這一行,看起來像是會導致這個問題的東西。 – Blender 2013-04-27 06:29:41

回答

2

正如Blender所說,應該沒有try_files你的上游在哪裏調用。

以下nginx的配置是足夠舉辦燒瓶應用:

server { 
    listen 80; 
    server_name ezte.ch; 

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

我燒瓶配置:

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

所以有路徑/無功/網絡/應用/ someapp /和瓶文件someapp .py

0

我有同樣的問題。只是刪除這條線從nginx的配置:

root /usr/share/nginx/www/eztech/public_html;