2016-09-16 36 views
0

新しいフラスコ/ nginx/uWSGIサーバー。アプリケーションの読み込みと機能は期待どおりですが、html/cssテンプレート以外のものが読み込まれます。 Chromeでデベロッパーツールを使用すると、ページが返されないことがわかります。NginxはFlask静的ファイルをロードしません

"tail -f /var/log/nginx/error.log"は、ファイルまたはディレクトリが存在しないことを示します。しかし、それは正しい経路のようです。フル・パスは、フラスコのデバッグはまったく問題を示していない「/opt/netmgmt/app/static/css/main.css」

2016/09/15 22:04:40 [error] 4939#0: *1 open() "/app/static/css/main.css" failed (2: No such file or directory), client: 10.0.0.69, server: , request: "GET /static/css/main.css HTTP/1.1", host: "nms-srv2", referrer: "http://nms-srv2/" 

です。 私はしばらくの間この頭と頭を叩いて、同じ問題を持つ複数の他のスレッドを見つけましたが、何も私のためにこれを解決していません。

ありがとうございました!

/etc/nginx/nginx.conf

worker_processes 1; 

events { 

worker_connections 1024; 

} 

http { 

    sendfile on; 

    gzip    on; 
    gzip_http_version 1.0; 
    gzip_proxied  any; 
    gzip_min_length 500; 
    gzip_disable  "MSIE [1-6]\."; 
    gzip_types  text/plain text/xml text/css 
         text/comma-separated-values 
         text/javascript 
         application/x-javascript 
         application/atom+xml; 

    # Configuration containing list of application servers 
    upstream uwsgicluster { 

     server 127.0.0.1:8080; 
     # server 127.0.0.1:8081; 
     # .. 
     # . 

    } 
    # Configuration for Nginx 
    server { 

     # Running port 
     listen 80; 

     # Settings to by-pass for static files 
     location ^~ /static/ { 

      # Example: 
      # root /full/path/to/application/static/file/dir; 
      root /app/; 

     } 

     # Serve a static file (ex. favico) outside static dir. 
     location = /favico.ico { 

      root /app/favico.ico; 

     } 

     # Proxying connections to application servers 
     location/{ 

      include   uwsgi_params; 
      uwsgi_pass   uwsgicluster; 

      proxy_redirect  off; 
      proxy_set_header Host $host; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header X-Forwarded-Host $server_name; 

     } 

アプリファイル(アイブは、静的位置複数の方法を変更しない運とエイリアス代わりのルートを使用してみました。)

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

レイアウト。 html

<!DOCTYPE html> 
<html> 
    <head> 
    <title>NetMgmt</title> 
    <strong><link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}"></strong> 
    </head> 
    <body> 
    <header> 
     <div class="container"> 
     <h1 class="logo">NetMgmt (beta)</h1> 
     <strong><nav> 
      <ul class="menu"> 
      <li><a href="{{ url_for('home') }}">Home</a></li> 
     </ul> 
     </nav></strong> 
     </div> 
    </header> 

    <div class="container"> 
     {% block content %} 
     {% endblock %} 
    </div> 
    </body> 
</html> 

答えて

0

nginx設定では、への絶対パスを使用してくださいディレクトリ。 staticは次のパスにある必要があります。

location ^~ /static/ { 
    root /full/path/to/app/static/; 
} 
+0

"root/opt/netmgmt/app/static /;"私はパス "/opt/netmgmt/app/static/static/css/main.cssを表示するのと同じエラーが表示されます。" root/opt/netmgmt/app /; "IEでは動作しますが、chrome/FFではエラーが発生しません"リソースはスタイルシートとして解釈されますが、MIMEタイプtext/plainで転送されます " – that1guy15

関連する問題