Nginx will not load Flask static files
<p>New flask/nginx/uWSGI server. Application loads and functions as expected but non of the html/css templates will load. Using developer tools in Chrome shows the pages are not being returned. </p>

<p>"tail -f /var/log/nginx/error.log" says the file or directory does not exist. But it appears to be the correct path. Full path is "/opt/netmgmt/app/static/css/main.css"</p>

<pre><code>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/"
</code></pre>

<p>Flask debugging shows no issue at all. 
Ive been banging my head against this one for a while and found multiple other threads with the same issue but nothing is solving this for me. </p>

<p>Thanks for the help!</p>

<p>/etc/nginx/nginx.conf</p>

<pre><code>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;

        }
</code></pre>

<p>App file (Ive tried changing the static location multiple ways and using alias instead of root with no luck.) </p>

<pre><code>@app.route('/')
def home():
  return render_template('home.html')
</code></pre>

<p>Layout.html</p>

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

    &lt;div class="container"&gt;
       {% block content %}
       {% endblock %}
    &lt;/div&gt;
  &lt;/body&gt;
 &lt;/html&gt;
</code></pre>

<p>In your nginx configuration use an absolute path to your <code>static</code> directory. <code>static</code> should be in the path:</p>

<pre><code>location ^~ /static/  {
    root /full/path/to/app/static/;
}
</code></pre>

python nginx flask uwsgi