原文:滚动查看最新信息,这是原帖
数据表似乎仅在http://server.com:9001直接导航到我的Django Web应用程序时才起作用,即使我已将所有HTTP流量代理到9001。
从http://server.com:9001/stores 查看时的屏幕截图
从http://server.com/stores 查看时的屏幕截图
数据表只是拒绝工作。更奇怪的是我在/服务器上有另一个数据表做同样的事情,但是/ closed-stores中相同的表一致地工作(我连续刷新了几十次尝试让它破坏它赢了“T)。
这些表中的每一个JS都只是$('#table-id').Datatable();
,但我会把它留下来,因为它显然有效,所以我相信它的我的Nginx.conf可能或者与Django有关吗?
我会注意到在所有情况下控制台中都有0个错误。
Nginx.conf
server {
listen 80 default_server;
#listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:9001;
}
location /static {
autoindex on;
alias /home/usr/applications/it-database/static/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
值得注意的是,这些表在我的Windows Server 2016开发服务器上运行了近两个月没有出现任何问题,但是当转移到CentOS时,这种情况就开始发生了。我只包括这个因为我完全不知道问题是什么。
更新1:经过一番挖掘,我发现问题是由于某种原因,我的上下文数据被某种方式切断了。如果我指定端口号,我将获得所有完整数据,因此表可以转换为数据表,但是当我没有指定端口号时,数据将在Store 386处被截止(有时更多,有时更少,总是在这个领域)。
我可以看到,在某些版本的Chrome中,访问/stores/
端点会产生net::ERR_CONTENT_LENGTH_MISMATCH
错误。很多人说,以前的版本,这是由于中间件订单,但后来已经解决。
我的中间件:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
/ stores / view:
@login_required
def stores(request):
stores = Store.objects.exclude(street_address__contains="closed").all()
context = {
'stores':stores,
}
return render(request, 'all_stores.html', context)
商店模板:
{% extends 'base.html' %}
{% block title %} All Stores - Stores Database {% endblock %}
{% block body %}
<br>
<div class="flex_container">
<h2>Store Database</h2>
<div class="table_header" style="float: left; position: relative;">
<br>
<h4>All Locations</h4>
</div>
<table id="store-table" class="table-striped table-hover">
<thead class="thead-light">
<tr>
<th>Store #</th>
<th>Name</th>
<th>Phone</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Circuit</th>
</tr>
</thead>
<tbody>
{% for store in stores %}
<tr id="table-row">
<td><a href="/stores/{{ store.pk }}">{{ store.store_number }}</a></td>
<td><a href="/stores/{{ store.pk }}">{{ store.name }}</a></td>
<td>{{ store.phone }}</td>
<td>{{ store.city }}</td>
<td>{{ store.state }}</td>
<td>{{ store.postal }}</td>
<td>
{% for circuit in store.circuit_set.all %}
<p>{{ circuit.circuit_id }}</p>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
$(document).ready(function () {
$('#store-table').DataTable();
});
</script>
{% endblock %}
这里的问题不一定与Django相关,而是更多的是Nginx如何处理代理与提供静态内容。为静态文件设置proxy_pass时,需要验证nginx用户是否可以访问/lib/nginx/proxy_tmp
。您的用户可能还需要访问其他重要目录,因此我只是拥有整个/lib/nginx
目录的所有权。
它在指定端口时提供的原因是因为我直接访问我的Gunicorn / Django应用程序,而不是通过Nginx代理,所以这个代理目录在那种情况下无关紧要。