英文:
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;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论