django+flup+nginx 静态文件的引用问题

林夕_信仰 发布于 2013/11/26 23:33
阅读 842
收藏 0

折腾了一晚上的部署,好不容易搞好了,但是静态文件却无法访问,页面各种丑陋

nginx和flup都装好了,没出什么问题。用python manage.py runserver是可以正常访问静态资源的

下面是一些有关静态文件的设置

SITE_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)),'..')
STATIC_ROOT = os.path.join(SITE_ROOT, 'static').replace('\\','/')
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    ('css', os.path.join(STATIC_ROOT, 'css')),
    ('js', os.path.join(STATIC_ROOT, 'js')),
    ('img', os.path.join(STATIC_ROOT, 'img')),
    ('bootstrap', os.path.join(STATIC_ROOT, 'bootstrap')),
    ('bootstrap-select',os.path.join(STATIC_ROOT, 'bootstrap-select')),
)



在总的url配置里,我加了这个

(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.STATIC_ROOT})



我不知道是不是和DEBUG什么的有关,我按照官网的增加了一个settings_production.py

#coding:utf-8
from django.conf import settings
from settings import *

DEBUG = TEMPLATE_DEBUG = False
DATABASE_NAME = 'ecdb'
DATABASE_USER = 'feng'
DATABASE_PASSWORD = '123'



原settings.py里是DEBUG = True  TEMPLATE_DEBUG = DEBUG
但是没有再进行额外的设置了,我不知道这个文件要怎么起作用。

最后我把nginx/conf/nginx.conf贴一下,有点长,是按照网上的资料替换的

#user  nobody; 
worker_processes  1; 
  
#error_log  logs/error.log; 
#error_log  logs/error.log  notice; 
#error_log  logs/error.log  info; 
  
#pid        logs/nginx.pid; 
  
  
events { 
    worker_connections  64; 
} 
  
  
http { 
    include       mime.types; 
    default_type  application/octet-stream; 
  
    #log_format  main  '$remote_addr - $remote_user [$time_local] $request ' 
    #                  '"$status" $body_bytes_sent "$http_referer" ' 
    #                  '"$http_user_agent" "$http_x_forwarded_for"'; 
  
    #access_log  logs/access.log  main; 
  
    sendfile        on; 
    #tcp_nopush     on; 
  
    #keepalive_timeout  0; 
    keepalive_timeout  65; 
  
    #gzip  on; 
  
    server { 
        listen       80; 
        server_name  localhost;
         
        #root   /cygdrive/D/html; 
        root   /cygdrive/F:\Project\EasyCollege; 
        # 使用哪行,调试一下 
        #root   F:\Project\EasyCollege; 
        index  index.html index.htm; 
  
        charset utf-8; 
  
        #access_log  logs/host.access.log  main; 
         
        location ^~ /media/ { 
                #alias        F:/Python27/Lib/site-packages/django/contrib/admin/media/; 
                #  使用哪行,调试一下 
                alias        /cygdrive/F/Python27/Lib/site-packages/django/contrib/admin/media/; 
        } 
        # 静态资源 
        location ~* ^.+/.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ 
        { 
                expires 30d; 
                break; 
        } 
  
        location / { 
            # 指定 fastcgi 的主机和端口 
            fastcgi_pass 127.0.0.1:8051; 
            fastcgi_param PATH_INFO $fastcgi_script_name; 
            fastcgi_param REQUEST_METHOD $request_method; 
            fastcgi_param QUERY_STRING $query_string; 
            fastcgi_param CONTENT_TYPE $content_type; 
            fastcgi_param CONTENT_LENGTH $content_length; 
            fastcgi_param SERVER_PROTOCOL $server_protocol; 
            fastcgi_param SERVER_PORT $server_port; 
            fastcgi_param SERVER_NAME $server_name; 
            fastcgi_pass_header Authorization; 
            fastcgi_intercept_errors off; 
        } 
  
        #error_page  404              /404.html; 
  
        # redirect server error pages to the static page /50x.html 
        # 
        error_page   500 502 503 504  /50x.html; 
        location = /50x.html { 
            root   html; 
        } 
  
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
        # 
        #location ~ /.php$ { 
        #    proxy_pass   http://127.0.0.1; 
        #} 
  
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
        # 
        #location ~ /.php$ { 
        #    root           html; 
        #    fastcgi_pass   127.0.0.1:9000; 
        #    fastcgi_index  index.php; 
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; 
        #    include        fastcgi_params; 
        #} 
  
        # deny access to .htaccess files, if Apache's document root 
        # concurs with nginx's one 
        # 
        #location ~ //.ht { 
        #    deny  all; 
        #} 
    } 


   # another virtual host using mix of IP-, name-, and port-based configuration 
   # 
   #server { 
   #    listen       8000; 
   #    listen       somename:8080; 
   #    server_name  somename  alias  another.alias; 

   #    location / { 
   #        root   html; 
   #        index  index.html index.htm; 
   #    } 
   #} 


   # HTTPS server 
   # 
   #server { 
   #    listen       443; 
   #    server_name  localhost; 

   #    ssl                  on; 
   #    ssl_certificate      cert.pem; 
   #    ssl_certificate_key  cert.key; 

   #    ssl_session_timeout  5m; 

   #    ssl_protocols  SSLv2 SSLv3 TLSv1; 
   #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; 
   #    ssl_prefer_server_ciphers   on; 

   #    location / { 
   #        root   html; 
   #        index  index.html index.htm; 
   #    } 
   #} 

}



这是控制台的出错信息:

这是项目截图,那些静态文件都是存在的

我能想到的和这个问题有关的资料就在上面了,需要额外信息可以补充。看那么长的信息,先谢谢大家了!

加载中
0
林夕_信仰
林夕_信仰

当我测试nginx配置的时候,显示是成功的

0
筱龙缘
筱龙缘
按照楼主的配置  我的也用不起来  
返回顶部
顶部