我有一个烧瓶应用程序我试图运行CentOS 6.6,Python 6.6,uwsgi 2.0.8和nginx 1.0.15。我禁用了selinux。
它使用flask运行,但在尝试使用nginx进行设置时,它正在显示网站,但没有应用任何CSS文件。
如果我查看网页源代码,它正确链接到CSS文件('/ static / css / style.css'),如果我从源代码打开它们打开它们,但它没有将它们应用于网页。但它会加载图像并显示它。
我正在使用wsgi ini文件运行它。 ($ flask / bin / uwsgi --ini uwsgi.ini)
我的wsgi.ini配置文件:
[uwsgi]
socket = 127.0.0.1:5000
chdir = /home/apps/portal
home = /home/apps/portal/flask
module = app:app
master = true
enable-threads = True
processes = 5
vacuum = True
我的nginx配置文件:
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile on;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;
upstream uwsgicluster {
server 127.0.0.1:5000;
}
server {
listen 80;
server_name localhost;
charset utf-8;
location /static {
alias /home/apps/portal/app/static;
}
location / {
include uwsgi_params;
uwsgi_pass uwsgicluster;
uwsgi_param UWSGI_CHDIR /home/apps/portal;
uwsgi_param UWSGI_PYHOME /home/apps/portal/flask;
uwsgi_param UWSGI_MODULE portal;
uwsgi_param UWSGI_CALLABLE app;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
nginx访问日志文件(/var/log/nginx/access.log):
110.143.38.80 - - [22/Dec/2014:12:23:26 +1000] "GET /user/admin HTTP/1.1" 200 3279 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
110.143.38.80 - - [22/Dec/2014:12:23:26 +1000] "GET /static/css/style.css HTTP/1.1" 200 1541 "http://*.*.*.*/user/admin" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
110.143.38.80 - - [22/Dec/2014:12:23:26 +1000] "GET /static/js/moment.min.js HTTP/1.1" 200 13111 "http://*.*.*.*/user/admin" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
110.143.38.80 - - [22/Dec/2014:12:23:26 +1000] "GET /static/js/bootstrap.min.js HTTP/1.1" 200 11339 "http://*.*.*.*/user/admin" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
110.143.38.80 - - [22/Dec/2014:12:23:26 +1000] "GET /static/css/bootstrap.min.css HTTP/1.1" 200 23863 "http://*.*.*.*/user/admin" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
110.143.38.80 - - [22/Dec/2014:12:23:26 +1000] "GET /static/upload/avatars/admin_guyfawkes.jpg HTTP/1.1" 200 38039 "http://*.*.*.*/user/admin" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
答案 0 :(得分:3)
由于Gohn67的建议,我在加载页面后检查了开发者控制台。控制台报道: "资源解释为样式表,但使用MIME类型text / plain"
进行传输之后我将include /etc/nginx/mime.types;
插入到nginx conf文件中,一切正常。