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

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

Cannot Configure (Error While) Django setting in nginx

问题

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

  1. user www-data;
  2. worker_processes auto;
  3. pid /run/nginx.pid;
  4. include /etc/nginx/modules-enabled/*.conf;
  5. events {
  6. worker_connections 768;
  7. }
  8. http {
  9. sendfile on;
  10. tcp_nopush off;
  11. tcp_nodelay off;
  12. keepalive_timeout 265;
  13. types_hash_max_size 2000;
  14. server {
  15. listen 8000;
  16. server_name joshna.co www.joshna.co joshna.net www.joshna.net;
  17. location = /favicon.ico { access_log off; log_not_found off; }
  18. location /static/{
  19. autoindex on;
  20. alias /home/bsyal/mysite/mypro/static;
  21. }
  22. location /media/{
  23. autoindex on;
  24. alias /home/bsyal/mysite/mypro-project/static;
  25. }
  26. location / {
  27. include proxy_params;
  28. proxy_pass http://unix:/run/gunicorn.sock;
  29. }
  30. }
  31. }

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

英文:

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

  1. user www-data;
  2. worker_processes auto;
  3. pid /run/nginx.pid;
  4. include /etc/nginx/modules-enabled/*.conf;
  5. events {
  6. worker_connections 768;
  7. }
  8. http {
  9. sendfile on;
  10. tcp_nopush off;
  11. tcp_nodelay off;
  12. keepalive_timeout 265;
  13. types_hash_max_size 2000;

and Server is

  1. server {
  2. listen 8000;
  3. server_name joshna.co www.joshna.co joshna.net www.joshna.net;
  4. location = /favicon.ico { access_log off; log_not_found off; }
  5. location /static/{
  6. autoindex on;
  7. alias /home/bsyal/mysite/mypro/static;
  8. }
  9. location /media/{
  10. autoindex on;
  11. alias /home/bsyal/mysite/mypro-project/static;
  12. }
  13. location / {
  14. include proxy_params;
  15. proxy_pass http://unix:/run/gunicorn.sock;
  16. }
  17. }

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配置如下:

  1. server {
  2. listen 80;
  3. server_name joshna.co www.joshna.co joshna.net www.joshna.net;
  4. location = /favicon.ico { access_log off; log_not_found off; }
  5. location /static/ {
  6. alias /home/bsyal/mysite/mypro-project/static/;
  7. }
  8. location /media/ {
  9. alias /home/bsyal/mysite/mypro-project/media/;
  10. }
  11. location / {
  12. include proxy_params;
  13. proxy_pass http://unix:/run/gunicorn.sock;
  14. }
  15. }
英文:

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:

  1. server {
  2. listen 80;
  3. server_name joshna.co www.joshna.co joshna.net www.joshna.net;
  4. location = /favicon.ico { access_log off; log_not_found off; }
  5. location /static/ {
  6. alias /home/bsyal/mysite/mypro-project/static/;
  7. }
  8. location /media/ {
  9. alias /home/bsyal/mysite/mypro-project/media/;
  10. }
  11. location / {
  12. include proxy_params;
  13. proxy_pass http://unix:/run/gunicorn.sock;
  14. }
  15. }

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:

确定