django1.10 静态文件配置

settings配置

# 网站引用静态文件时都会加上该地址,如:http://www.xxx.com/static/css/mini.css
STATIC_URL = '/static/' 

# 静态文件根目录,执行命令`python manage.py collectstatic`可以把静态文件都收集到该目录下
STATIC_ROOT = BASE_DIR + "/performance/static/" 


# 静态文件原始文件所在目录
STATICFILES_DIRS = (
    os.path.join(os.path.dirname(__file__), '../performance/templates/').replace('\\', '/'),
    # os.path.join(os.path.dirname(__file__), 'static/').replace('\\', '/'),
)

引用静态文件

在html模板中引入

    {% load static %}
    <link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet" type="text/css" />

开发环境不需要其他配置就可以直接请求静态文件

部署环境的配置(nginx为例)

在配置文件.conf文件中设置

upstream bbs1.linuxtone.com {
    server 127.0.0.1:8552;
}

server {
        listen       8555;
        server_name  auto1.apitest.com;
        index   index.php index.html index.htm;

    // 直接copy需要删掉注释:
    // 静态文件配置,static只是个别名,可以改成其他的别名
    // 目录root+static(D:/A/B/static/)是django的
    // settings中的STATIC_ROOT,需要能够找到实际的静态文件
    location ~ ^/static/ {
            root D:/A/B/;
            expires 30d; 
            break; 
        }

    location ~ ^/ {
             root    D:/A/;
             proxy_redirect off ;
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header REMOTE-HOST $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             client_max_body_size 50m;
             client_body_buffer_size 256k;
             proxy_connect_timeout 30;
             proxy_send_timeout 30;
             proxy_read_timeout 60;
             proxy_buffer_size 256k;
             proxy_buffers 4 256k;
             proxy_busy_buffers_size 256k;
             proxy_temp_file_write_size 256k;
             proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
             proxy_max_temp_file_size 128m;
             proxy_pass    http://bbs1.linuxtone.com;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值