django静态文件无法访问解决方案

nginx配置如下:

xml 复制代码
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       8000; #设置的nginx访问端口
        server_name  test;
        charset      utf-8;
        location /static {
            autoindex on;
            alias /home/mysite/static; #具体目录以您现场具体部署的目录为准
        }

    }
# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

写两套模板,一套用于开发,一套用于部署,视图中判断返回哪套

python 复制代码
    if settings.DEBUG:
        return render(request, "example.html", locals())
    else:
        return render(request, "example.html", locals())
相关推荐
小柯南敲键盘1 分钟前
Temu多语言商品图翻译实现方案
人工智能·python
霸道流氓气质19 分钟前
基于 Spring 事务同步机制的事务后置动作收集器 Starter 实践
java·后端·spring
威联通安全存储20 分钟前
TS-h1677AXU-RP在工程机械机器人弧焊中的部署
大数据·人工智能·python·机器人
IT_陈寒21 分钟前
Java线程池踩了个坑,任务居然默默消失了
前端·人工智能·后端
statistican_ABin41 分钟前
WHO各国预期寿命影响因素分析与轻量回归预测
大数据·人工智能·python·数据分析·回归
b130538100491 小时前
HarmonyOS开发实战:小分享-ForEach循环渲染与key生成策略
后端
程序员爱钓鱼1 小时前
配置 GoLand 与 VS Code 开发环境
前端·后端·go
程序员爱钓鱼1 小时前
Rust Vec 动态数组详解:创建、增删、遍历与排序
前端·后端·rust
超人不会飞_Jay1 小时前
Go课程2
开发语言·后端·golang
奶糖 肥晨1 小时前
一次Spring Boot编译报错排查:三元运算符与包装类型的“隐形陷阱”
java·spring boot·后端