python - Nginx not returning html templates correctly when connecting via dns -


hi i've made web application organisation i'm deploying onto ubuntu server. web application built in python flask , other extentions , works great in dev, when deploy weird error can't see purpose for.

  • application made flask
  • "front-end" nginx
  • uwsgi handling python nginx

  • the server running newest ubuntu server on wm

  • i can reach application computer in lan ip-adress in browser, works fine , assigned port 80 in nginx don't have type port myself. (flask congfigured localhost:8080 testing pursuses).

  • i can not server reply else 502 , 404 errors when trying connect through dns pointed @ outgoing ip, nor can connect directly outgoing ip. can see in 1 of error logs seems server handles request gets weird error 1 of flask "current_user" modules. dump logs can below.

/var/log/uwsgi/new-elf-lite_uwsgi.log containing python error

[pid: 1565|app: 0|req: 75/75] 192.168.1.1 () {46 vars in 831 bytes} [tue jan  5 23:08:17 2016] /nyheter => 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" 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] /nyheter => generated 0 bytes in 5 msecs (http/1.1 500) 0 headers in 0 bytes (0 switches on core 0) 

emperor.log looks fine

*** starting uwsgi 2.0.12 (64bit) on [tue jan  5 22:53:15 2016] *** compiled 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 pcre support !!! setgid() 33 setuid() 33 processes number limit 3846 memory page size 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable --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 disabled. can enable --enable-threads *** python main interpreter initialized @ 0x1b08b90 mercy graceful operations on workers 60 seconds *** operational mode: no-workers *** spawned uwsgi master process (pid: 1560) *** has_emperor mode detected (fd: 6) *** [uwsgi] getting ini configuration 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 ready accept requests tue jan  5 22:53:18 2016 - [emperor] vassal new-elf-lite_uwsgi.ini loyal elf@elfsite:/var/www/new-elf-lite$ 

/var/www/nginx/error.log think it's telling med failing when trying reach directory

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 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 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 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" 

new-elf-lite_uwsgi.ini

[uwsgi] #application's base folder base = /var/www/new-elf-lite  #python module 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 socket file chmod-socket    = 644  #the variable holds flask application inside module imported @ line #6 callable = app  #location of log files logto = /var/log/uwsgi/%n.log 

new-elf-lite_nginx.conf

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;     } } 

structure of application

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 make app run 

the project folder assigned user www-data:www-data, got chmod 777 on .sock.

thankful can get!

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__' 

current_user.is_authenticated return true or flase, call it, boolean value.

the solution simple, should use this, out ():

{% if current_user.is_authenticated %} 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -