2015-07-01 112 views
3

服務燒瓶應用程序我嘗試在我的網站上的子目錄上部署燒瓶,這個腳本超輕量,並且不需要(實際上不能)滾入主項目。當我走到終點的時候,我從瓶子裏得到一個404錯誤(可以確認它是瓶子,因爲日誌顯示活動)。我在我的nginx配置文件中傳遞uwsgi_param SCRIPT_NAME /upload;uwsgi_modifier1 30;,但這似乎不起作用。我怎樣才能得到uwsgi服務我的燒瓶應用程序在一個nginx子位置(子目錄)?在子目錄nginx + uwsgi

這裏是我的nginx的配置(在/上傳位置是麻煩的是):

upstream django { 
    server app0.api.xyz.com:9002; 
} 

server { 
    listen  443; 
    ssl on; 
    ssl_certificate /etc/nginx/ssl/cert_chain.crt; 
    ssl_certificate_key /etc/nginx/ssl/api_xyz.key; 

    charset  utf-8; 
    server_name dev.api.xyz.com; 

    location/{ 
      uwsgi_pass django; 
      include /etc/nginx/uwsgi_params; 
    } 

    location /media { 
      alias /var/xyzdata; 
    } 

    location /upload { 
     include /etc/nginx/uwsgi_params; 
     uwsgi_pass unix:/var/sockets/upload.sock; 
     uwsgi_param SCRIPT_NAME /upload; 
     uwsgi_modifier1 30; 
    } 
} 

我uwsgi.ini文件:

[uwsgi] 
chdir   = /home/ubuntu/uploadFlask 
module   = images 
callable  = app 
socket   = /var/sockets/upload.sock 
master   = true 
processes  = 10 
vacuum   = true 
uid    = www-data 
gid    = www-data 
daemonize  = /var/log/uploads/error.log 

最後我整個瓶的應用:

import os 
from flask import Flask, request, redirect, url_for,Response, jsonify 
from werkzeug import secure_filename 
import time 

UPLOAD_FOLDER = '/var/xyzdata' 
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) 

app = Flask(__name__) 
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER 
app.config['DEBUG'] = True 

@app.route('/<user>', methods=['POST']) 
def upload_file(user): 
    file = request.files['file'] 
    if file: 
      file_id = str(time.time()).replace('.','_') 
      filename = "{0}/images/{1}.jpg".format(user, file_id) 
      path = os.path.join(app.config['UPLOAD_FOLDER'], filename) 
      d = os.path.dirname(path) 
      if not os.path.exists(d): 
        os.makedirs(d) 
      file.save(path) 
      return jsonify(physical_path=path, virtual_path=filename, 
          id=file_id) 

@app.route('/delete/<user>/<id>/', methods=['POST']) 
def delete_file(user, id): 
    pass 

該腳本的重點是將圖像上傳到我的靜態服務器。我的實際應用程序坐在一個單獨的服務器上,這就是爲什麼這不能坐在那裏。

基本上我想要的是能夠去dev.api.xyz.com/upload/123/並點擊upload_file。我期待瀏覽器出現405錯誤,因爲它僅限於POST。但我得到一個404錯誤。這裏是一個瓶/ uwsgi日誌的輸出示例:

[pid: 27900|app: 0|req: 4/5] 50.199.33.84() {40 vars in 669 bytes} [Wed Jul 1 01:03:51 2015] GET /upload/[email protected] => generated 233 bytes in 0 msecs (HTTP/1.1 404) 2 headers in 72 bytes (1 switches on core 0) 

所以瓶子被擊中,但URL匹配不起作用。在此先感謝您的幫助。

+0

此處同樣的錯誤。 –

回答

1

最快捷的解決方案

mount = /upload=<scriptname> 

禮節性的解決方案,我

location ~ /upload(/.*) { 
    include /etc/nginx/uwsgi_params; 
    uwsgi_pass unix:/var/sockets/upload.sock; 
    uwsgi_param PATH_INFO "$1"; 
} 

希望這可以幫助你。歡呼聲