새 플라스크/nginx/uWSGI 서버. html/css 템플릿 중 예상대로 애플리케이션로드 및 기능이로드됩니다. Chrome에서 개발자 도구를 사용하면 페이지가 반환되지 않음을 알 수 있습니다.Nginx에서 Flask 정적 파일을로드하지 않습니다.
"tail -f /var/log/nginx/error.log"는 파일 또는 디렉토리가 존재하지 않는다고 말합니다. 그러나 올바른 경로 인 것으로 보입니다. 전체 경로
2016/09/15 22:04:40 [error] 4939#0: *1 open() "/app/static/css/main.css" failed (2: No such file or directory), client: 10.0.0.69, server: , request: "GET /static/css/main.css HTTP/1.1", host: "nms-srv2", referrer: "http://nms-srv2/"
플라스크 디버깅 전혀 문제를 보여줍니다 "/opt/netmgmt/app/static/css/main.css"입니다. Ive는 잠시 동안 내 머리를 두드리는 소리를 지었고 동일한 문제가있는 여러 개의 다른 스레드를 발견했지만 아무것도 해결하지 못했습니다.
도움 주셔서 감사합니다.
/etc/nginx/nginx.conf
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;
# Configuration containing list of application servers
upstream uwsgicluster {
server 127.0.0.1:8080;
# server 127.0.0.1:8081;
# ..
# .
}
# Configuration for Nginx
server {
# Running port
listen 80;
# Settings to by-pass for static files
location ^~ /static/ {
# Example:
# root /full/path/to/application/static/file/dir;
root /app/;
}
# Serve a static file (ex. favico) outside static dir.
location = /favico.ico {
root /app/favico.ico;
}
# Proxying connections to application servers
location/{
include uwsgi_params;
uwsgi_pass uwsgicluster;
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;
}
응용 프로그램 파일 (필자는 고정 위치에 여러 가지 방법을 변경하고 행운과 별명 대신 루트를 사용했습니다.)
@app.route('/')
def home():
return render_template('home.html')
레이아웃. html
<!DOCTYPE html>
<html>
<head>
<title>NetMgmt</title>
<strong><link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}"></strong>
</head>
<body>
<header>
<div class="container">
<h1 class="logo">NetMgmt (beta)</h1>
<strong><nav>
<ul class="menu">
<li><a href="{{ url_for('home') }}">Home</a></li>
</ul>
</nav></strong>
</div>
</header>
<div class="container">
{% block content %}
{% endblock %}
</div>
</body>
</html>
사용 "루트/옵션/netmgmt/응용 프로그램/정적 /;"
static
경로에 있어야합니다 나는 "/opt/netmgmt/app/static/static/css/main.css 경로를 보여주는 동일한 오류를 얻는다."root/opt/netmgmt/app /; "IE에서는 작동하지만 chrome/FF에는 오류가 없습니다"리소스가 스타일 시트로 해석되었지만 MIME 유형 텍스트/일반으로 전송 됨 " – that1guy15