Statische Dateien: Ubuntu + Bottle + Nginx + GUnicorn
Verfasst: Montag 14. Oktober 2019, 12:00
Hallo zusammen,
meine statischen Dateien werden leider in der oben genannten Konfiguration nicht gefunden...
Zuvor im Test unter Windows hatte es folgendermaßen funktioniert - eine Route für alle statischen Dateien sowie bei Templates der vollständige Pfad (was natürlich auch unschön ist):
Nun direkt auf einem Ubuntu-Server sieht meine Testdatei sieht folgendermaßen aus:
Die Verzeichnisstruktur sieht folgendermaßen aus:
Sollte nicht eigentlich bereits Nginx die statischen Dateien bereitstellen? Deshalb hatten wir extra eine Zeile in der Nginx-Serverblockkonfiguration eingefügt (in einem früheren Thema), hier nochmal die ganze Datei:
Hier mal ein Ausschnitt aus dem nginx-Access.log:
Und ein Ausschnitt aus dem nginx-Error.log:
Wieso sucht nginx im Verzeichnis /usr/share/nginx? Wo ist denn das konfiguriert?
Und wie kann man die Template-Pfade sinnvoll angeben (also nicht vollständig)?
Sorry für den langen Beitrag und viele Grüße,
dd0815
meine statischen Dateien werden leider in der oben genannten Konfiguration nicht gefunden...
Zuvor im Test unter Windows hatte es folgendermaßen funktioniert - eine Route für alle statischen Dateien sowie bei Templates der vollständige Pfad (was natürlich auch unschön ist):
Code: Alles auswählen
# Static Files
@app.route('/static/<filename:re:.*\.*>')
def send_lalacss(filename):
return static_file(filename, root='static')
##### Main #####
@app.route('/hello')
def hello():
...
return template('index', result=result, template_lookup=['c:/Daten/02_Projekte/Prj_008_Firma/50_Projekte/testBottle/static'] )
Code: Alles auswählen
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import mysql.connector
from mysql.connector import errorcode
import logging
import bottle
from bottle import Bottle, route, run, template, static_file
from bottle import get, post, request
@route('/static/<filepath:path>')
def hallo(filepath):
#return static_file(filepath, root='/var/www/mserp/html/static/')
return static_file(filepath, root='/var/www/mserp/html/')
# a basic URL route to test whether Bottle is responding properly
@route('/')
def index():
result = [[1, 2, 3, "anl1", "Anlage 1"], [4, 5, 6, "anl2", "Anlage 2"]]
return template('index', result=result, template_lookup=['/var/www/mserp/html/static/'])
# these two lines are only used for python app.py
if __name__ == '__main__':
run(host='0.0.0.0', port=8080, debug=True, reloader=True)
# this is the hook for Gunicorn to run Bottle
app = bottle.default_app()
Code: Alles auswählen
/var/www/mserp/html/
├── bottle.py
├── static
│ ├── context.js
│ ├── images
│ │ ├── logo.png
│ │ └── suche.svg
│ ├── index.tpl
│ ├── main.js
│ └── mystyle.css
├── testApp2.py
Code: Alles auswählen
server {
listen 8080;
listen [::]:8080;
server_name _;
# declar proxy params and values to forward to your gunicorn webserver
proxy_pass_request_headers on;
proxy_pass_request_body on;
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_read_timeout 120s;
#
location /mserp {
# try_files $uri $uri/ =404;
# statische Daten
#root /var/www/mserp/static;
#root /var/www/mserp/html/;
root /var/www/mserp/html/static;
# here is where you declare that every request to /
# should be proxy to 127.0.0.1:8000 (which is where
# your gunicorn will be running on)
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
# the actual nginx directive to forward the request
proxy_pass http://127.0.0.1:8000/;
}
}
Code: Alles auswählen
172.21.6.18 - - [14/Oct/2019:10:48:37 +0000] "GET /mserp HTTP/1.1" 200 988 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
172.21.6.18 - - [14/Oct/2019:10:48:37 +0000] "GET /static/mystyle.css HTTP/1.1" 404 152 "http://172.21.3.4:8080/mserp" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
172.21.6.18 - - [14/Oct/2019:10:48:37 +0000] "GET /static/main.js HTTP/1.1" 404 152 "http://172.21.3.4:8080/mserp" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
172.21.6.18 - - [14/Oct/2019:10:48:37 +0000] "GET /static/context.js HTTP/1.1" 404 152 "http://172.21.3.4:8080/mserp" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
172.21.6.18 - - [14/Oct/2019:10:48:37 +0000] "GET /static/images/logo.png HTTP/1.1" 404 152 "http://172.21.3.4:8080/mserp" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
172.21.6.18 - - [14/Oct/2019:10:48:37 +0000] "GET /static/context.js HTTP/1.1" 404 152 "http://172.21.3.4:8080/mserp" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
172.21.6.18 - - [14/Oct/2019:10:48:37 +0000] "GET /static/images/logo.png HTTP/1.1" 404 152 "http://172.21.3.4:8080/mserp" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
Code: Alles auswählen
2019/10/14 10:48:37 [error] 33822#33822: *3 open() "/usr/share/nginx/html/static/main.js" failed (2: No such file or directory), client: 172.21.6.18, server: _, request: "GET /static/main.js HTTP/1.1", host: "172.21.3.4:8080", referrer: "http://172.21.3.4:8080/mserp"
2019/10/14 10:48:37 [error] 33822#33822: *4 open() "/usr/share/nginx/html/static/context.js" failed (2: No such file or directory), client: 172.21.6.18, server: _, request: "GET /static/context.js HTTP/1.1", host: "172.21.3.4:8080", referrer: "http://172.21.3.4:8080/mserp"
2019/10/14 10:48:37 [error] 33822#33822: *1 open() "/usr/share/nginx/html/static/images/logo.png" failed (2: No such file or directory), client: 172.21.6.18, server: _, request: "GET /static/images/logo.png HTTP/1.1", host: "172.21.3.4:8080", referrer: "http://172.21.3.4:8080/mserp"
2019/10/14 10:48:37 [error] 33822#33822: *1 open() "/usr/share/nginx/html/static/context.js" failed (2: No such file or directory), client: 172.21.6.18, server: _, request: "GET /static/context.js HTTP/1.1", host: "172.21.3.4:8080", referrer: "http://172.21.3.4:8080/mserp"
2019/10/14 10:48:37 [error] 33822#33822: *1 open() "/usr/share/nginx/html/static/images/logo.png" failed (2: No such file or directory), client: 172.21.6.18, server: _, request: "GET /static/images/logo.png HTTP/1.1", host: "172.21.3.4:8080", referrer: "http://172.21.3.4:8080/mserp"
Und wie kann man die Template-Pfade sinnvoll angeben (also nicht vollständig)?
Sorry für den langen Beitrag und viele Grüße,
dd0815