Nginx not returning html templates correctly when connecting via dns
<p>Hi i've made a web application for my organisation that i'm currently deploying onto an ubuntu server. The web application is built in python with flask and some other extentions and it works great in dev, but when i deploy it i get some weird error that i can't see the purpose for.</p>

<ul>
<li>Application is made with flask</li>
<li>"front-end" is nginx</li>
<li><p>uwsgi is handling the python for nginx</p></li>
<li><p>The server is running the newest ubuntu server on a WM</p></li>
<li><p>I <strong>can</strong> reach the application from another computer in my LAN by its ip-adress in my browser, works fine and is assigned to port 80 in nginx so i don't have to type any port by myself. (flask itself was congfigured to localhost:8080 for testing pursuses).</p></li>
<li><p><strong>I CAN NOT</strong> get the server to reply anything else than 502 and 404 errors when i am trying to connect through my dns pointed at my outgoing ip, nor can i connect directly to the outgoing ip. But what i can see in one of the error logs is that it seems like the server handles my request but gets a weird error with one of the flask "current_user" modules. I will dump all the logs i can below.</p></li>
</ul>

<p><strong><em>/var/log/uwsgi/new-elf-lite_uwsgi.log containing the python error</em></strong></p>

<pre><code>[pid: 1565|app: 0|req: 75/75] 192.168.1.1 () {46 vars in 831 bytes} [Tue Jan  5 23:08:17 2016] GET /nyheter =&gt; generated 0 bytes in 10 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
Traceback (most recent call last):
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/new-elf-lite/app/views.py", line 36, in nyheter
    return render_template('news.html', title = title, news = news)
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/templating.py", line 128, in render_template
    context, ctx.app)
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask/templating.py", line 110, in _render
    rv = template.render(context)
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/new-elf-lite/app/templates/news.html", line 2, in top-level template code
    {% import "bootstrap/wtf.html" as wtf %}
  File "/var/www/new-elf-lite/app/templates/base.html", line 1, in top-level template code
    {% extends "bootstrap/base.html" %}
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 1, in top-level template code
    {% block doc -%}
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 4, in block "doc"
    {%- block html %}
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 20, in block "html"
    {% block body -%}
  File "/var/www/new-elf-lite/venv/local/lib/python2.7/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 21, in block "body"
    {% block navbar %}
  File "/var/www/new-elf-lite/app/templates/base.html", line 71, in block "navbar"
    {% if current_user.is_authenticated() %}
AttributeError: 'bool' object has no attribute '__call__'
[pid: 1565|app: 0|req: 76/76] 192.168.1.1 () {46 vars in 831 bytes} [Tue Jan  5 23:08:18 2016] GET /nyheter =&gt; generated 0 bytes in 5 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
</code></pre>

<p><strong><em>emperor.log looks fine</em></strong></p>

<pre><code>*** Starting uWSGI 2.0.12 (64bit) on [Tue Jan  5 22:53:15 2016] ***
compiled with version: 5.2.1 20151010 on 05 January 2016 20:57:28
os: Linux-4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015
nodename: ELFSITE
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /
detected binary path: /var/www/new-elf-lite/venv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
setgid() to 33
setuid() to 33
your processes number limit is 3846
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
Python version: 2.7.10 (default, Oct 14 2015, 16:09:02)  [GCC 5.2.1 20151010]
*** starting uWSGI Emperor ***
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1b08b90
your mercy for graceful operations on workers is 60 seconds
*** Operational MODE: no-workers ***
spawned uWSGI master process (pid: 1560)
*** has_emperor mode detected (fd: 6) ***
[uWSGI] getting INI configuration from new-elf-lite_uwsgi.ini
Tue Jan  5 22:53:15 2016 - [emperor] vassal new-elf-lite_uwsgi.ini has been spawned
Tue Jan  5 22:53:15 2016 - [emperor] vassal new-elf-lite_uwsgi.ini is ready to accept requests
Tue Jan  5 22:53:18 2016 - [emperor] vassal new-elf-lite_uwsgi.ini is now loyal
elf@ELFSITE:/var/www/new-elf-lite$
</code></pre>

<p><strong><em>/var/www/nginx/error.log I think it's telling med that it is failing when trying to reach the directory</em></strong></p>

<pre><code>2016/01/05 23:07:49 [error] 1599#0: *42 open() "/var/www/new-elf-lite/app/static/static/img/logotype_black.png" failed (2: No such file or directory), client: 192.168.1.44, server: localhost, request: "GET /static/img/logotype_black.png HTTP/1.1", host: "192.168.1.167", referrer: "http://192.168.1.167/nyheter"
2016/01/05 23:08:17 [error] 1599#0: *38 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.1, server: localhost, request: "GET /nyheter HTTP/1.1", upstream: "uwsgi://unix:/var/www/new-elf-lite/new-elf-lite_uwsgi.sock:", host: "game.montell.se"
2016/01/05 23:08:17 [error] 1599#0: *38 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.1, server: localhost, request: "GET /nyheter HTTP/1.1", upstream: "uwsgi://unix:/var/www/new-elf-lite/new-elf-lite_uwsgi.sock:", host: "game.montell.se"
2016/01/05 23:08:18 [error] 1599#0: *38 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.1, server: localhost, request: "GET /nyheter HTTP/1.1", upstream: "uwsgi://unix:/var/www/new-elf-lite/new-elf-lite_uwsgi.sock:", host: "game.montell.se"
</code></pre>

<p><strong><em>new-elf-lite_uwsgi.ini</em></strong></p>

<pre><code>[uwsgi]
#application's base folder
base = /var/www/new-elf-lite

#python module to import
app = run
module = %(app)

home = %(base)/venv
pythonpath = %(base)

#socket file's location
socket = /var/www/new-elf-lite/new-elf-lite_uwsgi.sock

#permissions for the socket file
chmod-socket    = 644

#the variable that holds a flask application inside the module imported at line #6
callable = app

#location of log files
logto = /var/log/uwsgi/%n.log
</code></pre>

<p><strong><em>new-elf-lite_nginx.conf</em></strong></p>

<pre><code>server {
    listen      80;
    server_name localhost;
    charset     utf-8;
    client_max_body_size 750M;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/var/www/new-elf-lite/new-elf-lite_uwsgi.sock;
    }
    location /static {
        root /var/www/new-elf-lite/app/static;
    }
    location /templates {
        root /var/www/new-elf-lite/app/templates;
    }
}
</code></pre>

<p><strong><em>Structure of the application</em></strong></p>

<pre><code>new-elf-lite/
----run.py
----new-elf-lite_uwsgi.ini
----new-elf-lite_uwsgi.sock
----new-elf-lite_nginx.conf
----app/
--------static/
----------------css/
--------------------style.css
----------------img/
--------------------logotype.png
--------templates/
------------(all non-permission htmls)
------------admin/
----------------(all admin htmls)
------------moderator/
----------------(all moderator htmls)
--------Etc to make the app run
</code></pre>

<p>The project folder is assigned to the user www-data:www-data, even got chmod 777 on .sock.</p>

<p>Thankful for all help i can get!</p>