Tag: 静态文件

使用nginx从给定目录的子目录提供静态文件

我在我的服务器上有几组静态.html文件,我想用nginx直接提供服务。 例如,nginx应该提供以下模式的URI: www.mysite.com/public/doc/foo/bar.html 与位于/home/www-data/mysite/public/doc/foo/bar.html的.html文件相关/home/www-data/mysite/public/doc/foo/bar.html 。 您可以将foo视为设置名称,并将其作为文件名称。 我不知道是否接下来的nginxconfiguration会做这个工作: server { listen 8080; server_name www.mysite.com mysite.com; error_log /home/www-data/logs/nginx_www.error.log; error_page 404 /404.html; location /public/doc/ { autoindex on; alias /home/www-data/mysite/public/doc/; } location = /404.html { alias /home/www-data/mysite/static/html/404.html; } } 换句话说,模式/public/doc/…/….html中的所有请求都将由nginx处理,如果找不到任何给定的URI,则默认为www.mysite.com/404.html被返回。

Django – 无法获取静态CSS文件加载

我在本地计算机(Mac OS X)上运行Django的开发服务器( runserver ),无法加载CSS文件。 以下是settings.py中的相关条目: STATIC_ROOT = '/Users/username/Projects/mysite/static/' STATIC_URL = '/static/' STATICFILES_DIRS = ( '/Users/thaymore/Projects/mysite/cal/static', ) STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', #'django.contrib.staticfiles.finders.DefaultStorageFinder', ) INSTALLED_APPS = ( # other apps … 'django.contrib.staticfiles', ) 在我的views.py我要求的上下文: return render_to_response("cal/main.html",dict(entries=entries),context_instance=RequestContext(request)) 在我的模板中, {{ STATIC_URL }}呈现正确: <link type="text/css" href="{{ STATIC_URL }}css/main.css" /> 变成: <link type="text/css" href="/static/css/main.css"/> 这是文件实际位于的位置。 我也运行了collectstatic ,以确保collectstatic所有的文件。 我的urls.py中也有以下几行: from […]

Django – 找不到静态文件

我已经看到这个问题的几个职位,但没有find我的解决scheme。 我试图在我的Django 1.3开发环境中提供静态文件。 这是我的设置 … STATIC_ROOT = '/home/glide/Documents/django/cbox/static/' STATIC_URL = '/static/' STATICFILES_DIRS = ( '/static/', ) … 我的urls.py urlpatterns = patterns('', … url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root', settings.STATIC_ROOT} ), … ); 我的/ home / glide / Documents / django / cbox / static /目录就像 css main.css javascript image 尝试访问http://127.0.0.1:8000/static/css/main.css时遇到404错误。 我是否必须分别指定CSS,JavaScript和图像的模式?

如何直接使用NGINX服务所有现有的静态文件,但将其余的代理代理到后端服务器。

location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; if (-f $request_filename) { access_log off; expires 30d; break; } if (!-f $request_filename) { proxy_pass http://127.0.0.1:8080; # backend server listening break; } } 上面将直接使用Nginx提供所有现有的文件(例如Nginx只显示PHP源代码),否则将请求转发给Apache。 我需要从规则中排除* .php文件,以便对* .php的请求也传递给Apache并进行处理。 我希望Nginx处理所有的静态文件和Apache来处理所有的dynamic的东西。 编辑:有白名单的方法,但它不是很优雅,看到所有这些扩展名,我不想这个。 location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ { access_log off; expires 30d; } location / { proxy_set_header X-Real-IP […]

如何在Flask中提供静态文件

所以这很尴尬。 我有一个应用程序,我扔在一起Flask ,现在它只是提供一个静态的HTML页面,一些链接到CSS和JS。 而且我无法findFlask描述的返回静态文件的位置。 是的,我可以使用render_template但我知道数据不是模板化的。 我以为send_file或url_for是正确的,但我无法让这些工作。 与此同时,我正在打开文件,阅读内容,并安装适当的mimetype Response : import os.path from flask import Flask, Response app = Flask(__name__) app.config.from_object(__name__) def root_dir(): # pragma: no cover return os.path.abspath(os.path.dirname(__file__)) def get_file(filename): # pragma: no cover try: src = os.path.join(root_dir(), filename) # Figure out how flask returns static files # Tried: # – render_template # – send_file […]