gpt4 book ai didi

python - nginx/uwsgi/flask 不在模板中使用 CSS 文件

转载 作者:行者123 更新时间:2023-11-30 23:16:43 29 4
gpt4 key购买 nike

我有一个 Flask 应用程序,我正在尝试在 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"

最佳答案

由于 Gohn67 的建议,我在加载页面后检查了开发者控制台。控制台报告: “资源解释为样式表,但使用 MIME 类型文本/纯文本进行传输”

之后,我将 include/etc/nginx/mime.types; 插入到 nginx conf 文件中,一切正常。

关于python - nginx/uwsgi/flask 不在模板中使用 CSS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27595893/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com