Rails - Nginx + Puma - Statische Assets, die nicht von Nginx bereitgestellt werden, über den bereitgestellten Tutorial-Link
Ich benutze Ubuntu. Hier ist derLernprogramm
Nginx Config verwende ich:
upstream my_app {
server unix:///home/uname/railsproject/my_app.sock;
}
server {
listen 88; #(I used exact 88 when I am testing now)
server_name localhost; # I used exact localhost when I am testing this
root /home/uname/railsproject/public; # I assume your app is located at that location
location / {
proxy_pass http://my_app; # match the name of upstream directive which is defined above
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~* ^/assets/ {
# Per RFC2616 - 1 year maximum expiry
expires 1y;
add_header Cache-Control public;
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
add_header Last-Modified "";
add_header ETag "";
break;
}
}
Puma Befehl
RAILS_ENV=production puma -e production -b unix:///home/uname/railsproject/my_app.sock -p 8000
In der Adressleiste schreibe ich
http://localhost/
und dann Website öffnen, aber statische Assets funktionieren nicht. Natürlich bin ich gerannt
RAILS_ENV=production rake assets:precompile
und Assets sind im Ordner public / assets verfügbar
Ich habe auch versucht zu platzierenm.txt
Datei im Assets-Verzeichnis und Zugriff
http://localhost/assets/m.txt
hat aber nicht funktioniert. Ich habe auch diesen Befehl ausprobiert:
sudo chown -R www-data:www-data public/
aber das hat nicht geholfen.