我有一个 django 应用程序,它在 django 服务器上运行良好。我刚刚将其配置为与 nginx 和 gunicorn 一起工作。除了其中一个页面外,几乎每个页面都运行良好。这是一个相当大的页面,包含 4 个选择(下拉)菜单,每个菜单有 1000 个条目,所有这些都由 guinicorn 通过单个 html 文件发送。Gunicorn 只显示页面的一半。同样有趣的是,如果没有 nginx,gunicorn 可以很好地显示整个页面。尽管生成的页面不是静态的,但出于某种原因,nginx 会破坏页面。
这是我的 nginx 配置:
ec2-user@ip-172-31-44-39:~/mira_website> sudo cat /etc/nginx/sites-available/miraFrontEnd
# This is example contains the bare minimum to get nginx going with
# Gunicornservers.
worker_processes 1;
user ec2-user nogroup; # for systems with a "nogroup"
# user nobody nobody; # for systems with "nobody" as a group instead
# Feel free to change all paths to suit your needs here, of course
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;
events {
worker_connections 1024; # increase if you have lots of clients
accept_mutex off; # "on" if nginx worker_processes > 1
# use epoll; # enable for Linux 2.6+
# use kqueue; # enable for FreeBSD, OSX
}
http {
# nginx will find this file in the config directory set at nginx build time
# include mime.types;
# fallback in case we can't determine a type
default_type application/octet-stream;
# click tracking!
access_log /tmp/nginx.access.log combined;
# you generally want to serve static files with nginx since neither
# Unicorn nor Rainbows! is optimized for it at the moment
sendfile on;
tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
tcp_nodelay off; # on may be better for some Comet/long-poll stuff
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/html text/xml text/css
text/comma-separated-values
text/javascript application/x-javascript
application/atom+xml;
upstream app_server {
# for UNIX domain socket setups:
server unix:/home/ec2-user/gunicorn.sock fail_timeout=0;
# for TCP setups, point these to your backend servers
# server 192.168.0.7:8080 fail_timeout=0;
# server 192.168.0.8:8080 fail_timeout=0;
# server 192.168.0.9:8080 fail_timeout=0;
}
server {
# listen 80 default deferred; # for Linux
# listen 80 default accept_filter=httpready; # for FreeBSD
listen 8000;
client_max_body_size 4G;
server_name _;
keepalive_timeout 10;
location /static {
autoindex on;
alias /home/ec2-user/mira_website/manageDb/static/;
}
location / {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
# an HTTP header important enough to have its own Wikipedia entry:
# http://en.wikipedia.org/wiki/X-Forwarded-For
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# enable this if and only if you use HTTPS, this helps Rack
# set the proper protocol for doing redirects:
# proxy_set_header X-Forwarded-Proto https;
# pass the Host: header from the client right along so redirects
# can be set properly within the Rack application
proxy_set_header Host $http_host;
# we don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
proxy_pass http://app_server;
}
# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
root /path/to/app/current/public;
}
}
}
该服务器在搭载 Suse Linux 的 amazon ec2 上运行。
有任何想法吗?
编辑:好吧,这很有趣,我清除了浏览器的缓存、历史记录、cookie 和所有内容,它开始工作了。然后,几分钟后再试一次,它又出现了同样的问题。所以看起来,当我清除缓存时,它开始工作,但只持续了一段时间(奇怪!)。
答案1
我尝试了很多不同的配置,并使其正常工作,但我不确定实际情况如何。我认为情况是 指令调用的proxy_buffering
。现在将其设置为off
。
此外,可能解决此问题的方法是设置proxy_buffer_size size
。这里是关于该指令的官方文档。