无法在nginx中配置(Error While)Django设置

tjvv9vkg  于 2023-04-20  发布在  Nginx
关注(0)|答案(1)|浏览(129)

我的服务器找不到文件,它说没有找到文件。我有以下配置

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
       
}

http {

       

        sendfile on;
        tcp_nopush off;
        tcp_nodelay off;
        keepalive_timeout 265;
        types_hash_max_size 2000;

服务器是

server {
    listen 8000;
    server_name joshna.co www.joshna.co joshna.net www.joshna.net;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/{
    autoindex on;
    alias /home/bsyal/mysite/mypro/static;
}
    location /media/{
    autoindex on;
    alias /home/bsyal/mysite/mypro-project/static;
}
    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

服务器找不到文件,我已经通过别人的解决方案,但无法解决

qij5mzcb

qij5mzcb1#

而不是Nginx,这是因为你的Django静态配置。你需要从不同的目录提供静态和媒体文件。
创建两个目录(目录“/home/egor/mysite/mypro-project/static”和“/home/egor/mysite/mypro-project/media”存在),如果还没有,请更新Nginx配置如下:

server {
listen 80;
server_name joshna.co www.joshna.co joshna.net www.joshna.net;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    alias /home/bsyal/mysite/mypro-project/static/;
}
location /media/ {
    alias /home/bsyal/mysite/mypro-project/media/;
}
location / {
    include proxy_params;
    proxy_pass http://unix:/run/gunicorn.sock;
}
}

相关问题