我正在使用 Ubuntu。这是教程
我正在使用的 Nginx 配置:
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;
}
}
彪马命令
RAILS_ENV=production puma -e production -b unix:///home/uname/railsproject/my_app.sock -p 8000
在地址栏中,我正在输入
http://localhost/
然后网站打开但静态资产不起作用。当然,我跑了
RAILS_ENV=production rake assets:precompile
并且资产在 public/assets 文件夹中可用
我还尝试将m.txt
文件放在资产目录中并访问
http://localhost/assets/m.txt
但没有用。我也试过这个命令:
sudo chown -R www-data:www-data public/
但这没有帮助。