【发布时间】:2016-06-01 21:58:00
【问题描述】:
我正在尝试加载一些 Jpeg 格式的高分辨率图像,在 Django 制作中规格为 300dpi、5000 x 5000 分辨率。 以下是我在 digitalocean 的 nginx 设置:
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/django/django_project;
index index.html index.htm;
client_max_body_size 4G;
server_name localhost;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/django_project/media/;
}
# your Django project's static files - amend as required
location /static/django_project/ {
alias /home/django/django_project/static/django_project/;
}
# Django static images
location /static/django_project/images {
alias /home/django/django_project/static-only/django_project/images/;
}
# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
启用浏览缓存后:
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/django/django_project;
index index.html index.htm;
client_max_body_size 4G;
server_name mysite.com;
keepalive_timeout 5;
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
# Your Django project's media files - amend as required
location /media {
alias /home/django/django_project/media/;
}
# your Django project's static files - amend as required
location /static/django_project/ {
alias /home/django/django_project/static/django_project/;
}
# Django static images
location /static/django_project/images {
alias /home/django/django_project/static-only/django_project/images/;
}
# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
我在实时网站上的图片加载速度很慢。请建议或参考一些有用的资源来解决这个问题。
谢谢
【问题讨论】: