使用 RAILS_ENV=production rails s 启动 puma
2018/01/12 04:34:38 [error] 29429#0: *151 connect() to unix:///www/Haley_blog/shared/tmp/sockets/puma.sock failed (111: Connection refused) while connecting to upstream, client: 104.238.248.15, server: haleyme.com, request: "GET / HTTP/1.1", upstream: "http://unix:///www/Haley_blog/shared/tmp/sockets/puma.sock:/500.html", host: "www.HALEYME.com"
在我的 /www/Haley_blog/shared/log 下面没有自动生成 puma_access.log puma_error.log 两个文件 但是有 puma.stderr.log
puma.stdout.log 这两个文件
你需要看清 puma 和 nginx 的配置,而不是拷贝过来就用。
从 puma.rb 的内容看,如果设置了 RAILS_ENV=production,就使用 unix socket 的方式,需要启动 nginx 做反向代理才能访问。RAILS_ENV=production rails s
走的是这一分支。
如果没有设置 RAILS_ENV=production,就使用 puma 的默认配置,监听了 9292 端口。bundle exec puma -C config/puma.rb
走的是这一线路,当然也就没启动在生产环境。
先简化问题,你是要部署到生产环境还是本地开发?是在服务器调试还是本地调试?
这是 public 下面的 assets 下面的文件:
这是今天我看的 nginx 的错误日志 是 css js 文件没有加载起来
2018/01/12 22:20:31 [notice] 21737#0: signal process started
2018/01/12 22:21:41 [notice] 21802#0: signal process started
2018/01/12 22:24:18 [emerg] 21944#0: unexpected ";" in /etc/nginx/nginx.conf:23
2018/01/12 22:25:02 [notice] 21986#0: signal process started
2018/01/12 22:25:38 [notice] 22021#0: signal process started
2018/01/13 05:26:16 [emerg] 12975#0: invalid number of arguments in "add_header" directive in /etc/nginx/nginx.conf:26
2018/01/13 05:28:22 [notice] 13089#0: signal process started
2018/01/13 05:31:59 [error] 13242#0: *1 open() "/www/Haley_blog/current/public/assets/favicon-f6f0c8fbb6d88284f0cc080820c7796c1b34b09f5db22a244213a6d480f00e7e.ico" failed (2: No such file or directory), client: 64.233.172.185, server: haleyme.com, request: "GET /assets/favicon-f6f0c8fbb6d88284f0cc080820c7796c1b34b09f5db22a244213a6d480f00e7e.ico HTTP/1.1", host: "haleyme.com"
2018/01/13 06:03:57 [error] 13242#0: *12 open() "/www/Haley_blog/current/public/assets/application-8f4530a99f7e063bdaec68b187142c4abc9b4889a24465df284583f5af3912a1.js" failed (2: No such file or directory), client: 101.226.102.97, server: haleyme.com, request: "GET /assets/application-8f4530a99f7e063bdaec68b187142c4abc9b4889a24465df284583f5af3912a1.js HTTP/1.1", host: "haleyme.com", referrer: "http://haleyme.com/"
2018/01/13 14:45:10 [error] 13242#0: *68 open() "/www/Haley_blog/current/public/assets/application-8f4530a99f7e063bdaec68b187142c4abc9b4889a24465df284583f5af3912a1.js" failed (2: No such file or directory), client: 66.249.66.22, server: haleyme.com, request: "GET /assets/application-8f4530a99f7e063bdaec68b187142c4abc9b4889a24465df284583f5af3912a1.js HTTP/1.1", host: "haleyme.com", referrer: "http://haleyme.com/"
2018/01/13 14:45:10 [error] 13242#0: *71 open() "/www/Haley_blog/current/public/assets/application-fd38ec0d36a29c0e7147c4c03b1d9eaeddab725402721f277495b90984aae858.css" failed (2: No such file or directory), client: 66.249.66.24, server: haleyme.com, request: "GET /assets/application-fd38ec0d36a29c0e7147c4c03b1d9eaeddab725402721f277495b90984aae858.css HTTP/1.1", host: "haleyme.com", referrer: "http://haleyme.com/"
2018/01/13 15:27:04 [error] 13242#0: *80 open() "/www/Haley_blog/current/public/assets/application-fd38ec0d36a29c0e7147c4c03b1d9eaeddab725402721f277495b90984aae858.css" failed (2: No such file or directory), client: 66.249.66.4, server: haleyme.com, request: "GET /assets/application-fd38ec0d36a29c0e7147c4c03b1d9eaeddab725402721f277495b90984aae858.css HTTP/1.1", host: "haleyme.com", referrer: "http://haleyme.com/about"
ls /www/Haley_blog/current/public/assets/application-fd38ec0d36a29c0e7147c4c03b1d9eaeddab725402721f277495b90984aae858.css
看能不能找到文件。
那么修改 nginx 配置,root 去掉 current 目录,reload 配置。
current 是对应 cap 自动部署脚本生成的目录。
我把 nginx 配置文件的 current 去掉了 换成/www/Haley_blog/public 也重启了 nginx 服务器 也不知道是不是有缓存 还是不显示图片 puma 我也重启了,谷歌浏览器 我在设置里面清除了全部数据
现在访问 ip 图片 样式都可以正常加载了,但访问域名还是不显示图片,提示我访问资源终止了:
Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://haleyme.com/assets/application-030a2b8f546558a5ebff1f47fe1d87b47ec0567482a4f832eb87e4be8126b91d.css".
这个问题已经解决了。感谢各位的帮助 后面这个是 nginx 把 css 文件当成纯文本来加载了 在 nginx 配置文件中加上
include mime.types;
default_type application/octet-stream;
重启服务器就可以了
这里推荐使用 yum 的方式来安装 nginx,yum 安装的 nginx 包括了绝大部分模块,甚至包括 http2 的模块,还有一个就是他有一个比较完善的默认配置,包括 include mime.types 这样的配置都是默认有的