通过dns连接时,Nginx无法正确返回html模板

时间:2016-01-05 22:48:04

标签: python ubuntu nginx flask uwsgi

您好我为我的组织制作了一个网络应用程序,我目前正在部署到ubuntu服务器上。 Web应用程序是用python构建的,带有烧瓶和其他一些扩展,它在dev中工作得很好,但是当我部署它时,我得到一些奇怪的错误,我无法看到它的目的。

  • 用烧瓶进行施用
  • "前端"是nginx
  • uwsgi正在处理nginx的python

  • 服务器在WM上运行最新的ubuntu服务器

  • 可以通过我的浏览器中的ip-adress从我的局域网中的另一台计算机到达应用程序,工作正常并分配到nginx中的端口80,所以我不要必须自己键入任何端口。 (烧瓶本身被设置为localhost:8080用于测试追求)。

  • 我不能让我的服务器回复除502和404之外的任何错误,当我尝试通过我的dns指向我的传出ip连接,也不能直接连接到传出的IP。但是我可以在其中一个错误日志中看到,似乎服务器处理我的请求,但是其中一个烧瓶出现了一个奇怪的错误" current_user"模块。我将转储下面的所有日志。

包含python错误的

/var/log/uwsgi/new-elf-lite_uwsgi.log

[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 => 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 => generated 0 bytes in 5 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

emperor.log看起来不错

*** 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$

/var/www/nginx/error.log我认为它告诉医生在尝试访问目录时失败了

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"

新精灵-lite_uwsgi.ini

[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

新精灵-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;
    }
}

应用程序的结构

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

项目文件夹分配给用户www-data:www-data,甚至在.sock上获得chmod 777。

感谢我能得到的所有帮助!

1 个答案:

答案 0 :(得分:1)

True

Flase将返回(){% if current_user.is_authenticated %} ,但您调用它,它是一个布尔值。

解决方案很简单,你应该使用它,而不是double threshold = 0.7; Math.round(x - threshold + 0.5);

themes/
    aq-aquatics/
       css/
       img/
       js/
       footer.php
       functions.php
       header.php
       index.php
       page-homepage.php
       page-wide.php
       style.css
    index.php