Nginx仅为django应用程序提供部分静态文件

Nginx仅为django应用程序提供部分静态文件,django,nginx,static-files,Django,Nginx,Static Files,首先,我想声明,我已经阅读并尝试了所有关于该主题的问题的解答。 没什么帮助,但我的问题和平常的大不相同 我有一个django项目,它安装在我的开发计算机上(运行服务器和gunicorn上),这意味着提供静态文件。 值得一提的是,由于硬件问题,我最近将我的开发环境迁移到了fresh系统(这里的要点是我最近安装了这个项目) 当我尝试在另一个系统上安装它时(ubuntu 13.10的新安装,我已经为其编写了安装脚本),我遇到了一个奇怪的问题,不是所有的静态文件都由nginx提供服务。 “不是全部”意味

首先,我想声明,我已经阅读并尝试了所有关于该主题的问题的解答。
没什么帮助,但我的问题和平常的大不相同

我有一个django项目,它安装在我的开发计算机上(运行服务器和gunicorn上),这意味着提供静态文件。
值得一提的是,由于硬件问题,我最近将我的开发环境迁移到了fresh系统(这里的要点是我最近安装了这个项目)

当我尝试在另一个系统上安装它时(ubuntu 13.10的新安装,我已经为其编写了安装脚本),我遇到了一个奇怪的问题,不是所有的静态文件都由nginx提供服务。
“不是全部”意味着一些css文件被提供,一些没有;js也是如此

是的,所有的文件都在同一个静态目录中,是的,所有的文件都在那里。 另外,这可能不是配置问题,因为在这两种情况下(我的开发机器运行正常,而这个测试机器运行不正常),都有完全相同的配置。 文件的特权也是一样的。 nginx的日志中没有任何内容

这一定是非常愚蠢但充满异国情调的东西,或者我不知道。。。巫毒? 我的意思是,如果nginx不提供任何服务,我会设法做到这一点——这显然是一个错误——但为什么一个文件被提供,而另一个来自同一个地方的文件却没有? 还有,同一设置如何可能在一个系统上提供所有文件,而在另一个系统上仅提供少数文件

我没有在这里包括任何配置,因为正如我上面所说的,我认为它们在这里不是问题;然而,如果有人觉得有必要向自己保证,我很想贴出来,就说一句话

提前感谢各位,我请求帮助,我绝望而不感到羞耻。
已经过了三天了,截止日期还没到

My/etc/nginx/nginx.conf(基本上是默认值):

user www-data;                                                                  
worker_processes 4;                                                             
pid /run/nginx.pid;                                                             

events {                                                                        
    worker_connections 768;                                                 
    # multi_accept on;                                                      
}                                                                               

http {                                                                          

    ##                                                                      
    # Basic Settings                                                        
    ##                                                                      

    sendfile on;                                                            
    tcp_nopush on;                                                          
    tcp_nodelay on;                                                         
    keepalive_timeout 65;                                                   
    types_hash_max_size 2048;                                               
    # server_tokens off;                                                    

    # server_names_hash_bucket_size 64;                                     
    # server_name_in_redirect off;                                          

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

    ##                                                                      
    # Logging Settings                                                      
    ##                                                                      

    access_log /var/log/nginx/access.log;                                   
    error_log /var/log/nginx/error.log;                                     

    ##                                                                      
    # Gzip Settings                                                         
    ##                                                                      

    gzip on;                                                                
    gzip_disable "msie6";                                                   

    # gzip_vary on;                                                         
    # gzip_proxied any;                                                     
    # gzip_comp_level 6;                                                    
    # gzip_buffers 16 8k;                                                   
    # gzip_http_version 1.1;                                                
    # gzip_types text/plain text/css application/json application/x-javascript text/xmlapplication/xml applicatio

    ##                                                                      
    # nginx-naxsi config                                                    
    ##                                                                      
    # Uncomment it if you installed nginx-naxsi                             
    ##                                                                      

    #include /etc/nginx/naxsi_core.rules;   

    ##                                                                      
    # nginx-passenger config                                                
    ##                                                                      
    # Uncomment it if you installed nginx-passenger                         
    ##                                                                      

    #passenger_root /usr;                                                   
    #passenger_ruby /usr/bin/ruby;                                          

    ##                                                                      
    # Virtual Host Configs                                                  
    ##                                                                      

    include /etc/nginx/conf.d/*.conf;                                       
    include /etc/nginx/sites-enabled/*;                                     
}                                                                               


#mail {                                                                         
#       # See sample authentication script at:                                  
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript             
#                                                                               
#       # auth_http localhost/auth.php;                                         
#       # pop3_capabilities "TOP" "USER";                                       
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";                              
#                                                                               
#       server {                                                                
#               listen     localhost:110;                                       
#               protocol   pop3;                                                
#               proxy      on;                                                  
#       }                                                                       
#                                                                               
#       server {                                                                
#               listen     localhost:143;                                       
#               protocol   imap;                                                
#               proxy      on;                                                  
#       }                                                                       
#}         
server {                                                                        
listen 80;                                                                  
server_name webapp.org;                                                     

access_log /var/log/nginx_access.log;                                       
error_log /var/log/nginx_error.log;                                         

location /static {                                                          
    root /home/myuser/app;                                                 
}                                                                           

location /sse {                                                             
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;            
    proxy_set_header Host $http_host;                                       
    proxy_redirect off;                                                     
    proxy_buffering off;                                                    
    proxy_next_upstream error;                                              
    proxy_read_timeout 600;                                                 

    proxy_pass http://127.0.0.1:8888;                                       
}                                                                           

location /pacs {                                                            
    proxy_pass http://127.0.0.1:8080/;                                      
}                                                                           

location / {                                                                
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;            
    proxy_set_header Host $http_host;                                       
    proxy_redirect off;                                                     

    proxy_pass http://127.0.0.1:8888;                                       
}                                                                           
}                                 
已启用站点的站点配置:

user www-data;                                                                  
worker_processes 4;                                                             
pid /run/nginx.pid;                                                             

events {                                                                        
    worker_connections 768;                                                 
    # multi_accept on;                                                      
}                                                                               

http {                                                                          

    ##                                                                      
    # Basic Settings                                                        
    ##                                                                      

    sendfile on;                                                            
    tcp_nopush on;                                                          
    tcp_nodelay on;                                                         
    keepalive_timeout 65;                                                   
    types_hash_max_size 2048;                                               
    # server_tokens off;                                                    

    # server_names_hash_bucket_size 64;                                     
    # server_name_in_redirect off;                                          

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

    ##                                                                      
    # Logging Settings                                                      
    ##                                                                      

    access_log /var/log/nginx/access.log;                                   
    error_log /var/log/nginx/error.log;                                     

    ##                                                                      
    # Gzip Settings                                                         
    ##                                                                      

    gzip on;                                                                
    gzip_disable "msie6";                                                   

    # gzip_vary on;                                                         
    # gzip_proxied any;                                                     
    # gzip_comp_level 6;                                                    
    # gzip_buffers 16 8k;                                                   
    # gzip_http_version 1.1;                                                
    # gzip_types text/plain text/css application/json application/x-javascript text/xmlapplication/xml applicatio

    ##                                                                      
    # nginx-naxsi config                                                    
    ##                                                                      
    # Uncomment it if you installed nginx-naxsi                             
    ##                                                                      

    #include /etc/nginx/naxsi_core.rules;   

    ##                                                                      
    # nginx-passenger config                                                
    ##                                                                      
    # Uncomment it if you installed nginx-passenger                         
    ##                                                                      

    #passenger_root /usr;                                                   
    #passenger_ruby /usr/bin/ruby;                                          

    ##                                                                      
    # Virtual Host Configs                                                  
    ##                                                                      

    include /etc/nginx/conf.d/*.conf;                                       
    include /etc/nginx/sites-enabled/*;                                     
}                                                                               


#mail {                                                                         
#       # See sample authentication script at:                                  
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript             
#                                                                               
#       # auth_http localhost/auth.php;                                         
#       # pop3_capabilities "TOP" "USER";                                       
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";                              
#                                                                               
#       server {                                                                
#               listen     localhost:110;                                       
#               protocol   pop3;                                                
#               proxy      on;                                                  
#       }                                                                       
#                                                                               
#       server {                                                                
#               listen     localhost:143;                                       
#               protocol   imap;                                                
#               proxy      on;                                                  
#       }                                                                       
#}         
server {                                                                        
listen 80;                                                                  
server_name webapp.org;                                                     

access_log /var/log/nginx_access.log;                                       
error_log /var/log/nginx_error.log;                                         

location /static {                                                          
    root /home/myuser/app;                                                 
}                                                                           

location /sse {                                                             
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;            
    proxy_set_header Host $http_host;                                       
    proxy_redirect off;                                                     
    proxy_buffering off;                                                    
    proxy_next_upstream error;                                              
    proxy_read_timeout 600;                                                 

    proxy_pass http://127.0.0.1:8888;                                       
}                                                                           

location /pacs {                                                            
    proxy_pass http://127.0.0.1:8080/;                                      
}                                                                           

location / {                                                                
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;            
    proxy_set_header Host $http_host;                                       
    proxy_redirect off;                                                     

    proxy_pass http://127.0.0.1:8888;                                       
}                                                                           
}                                 

您直接访问的是Django dev服务器,它为您的一些静态文件提供服务。如果他们没有签入版本控制,你可能会留下一些,我不知道

无论如何,您必须访问Nginx,即在地址栏中键入:

http://your.server.com
而不是

http://your.server.com:8888
这样,您应该开始在Nginx访问日志中看到一些内容

另外,请记住运行collectstatic:

两个问题。1) 你所说的“未送达”是什么意思?当请求该文件时,nginx返回什么?2) “nginx的日志中没有任何内容”是什么意思?什么都没有?是的,发布你的nginx配置和日志(如果有的话)肯定会帮助这里的人们了解可能发生的事情。1)它返回404 2)什么都没有…你不能在日志中得到“什么都没有”。。。请参阅为nginx启用访问和错误日志。很显然,我可以:/(或者可能我搞错了,我发布了配置)非常感谢您的耐心和帮助!