无法在nginx中配置Django设置(出现错误)

huangapple go评论64阅读模式
英文:

Cannot Configure (Error While) Django setting in nginx

问题

我的服务器无法找到文件,显示没有找到文件。我有以下配置:

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;
        }
    }
}

服务器无法找到文件,我已经查看了其他解决方案,但没有找到解决方法。

英文:

My server cannot find the files, it says no files found . I have following configuration

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;

and Server is

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;
    }
}

Server cannot find file, I have gone thhrough others solution but could not figured out

答案1

得分: 1

除了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;
    }
}
英文:

Instead of Nginx, it is because of your Django static configuration. You need , static and media files to be served from different directories.

Create two directories (the directories "/home/egor/mysite/mypro-project/static" and "/home/egor/mysite/mypro-project/media" exist ) if not there already and update your Nginx configuration as follows:

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;
    }
}

huangapple
  • 本文由 发表于 2023年4月20日 00:51:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057031.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定