0

我很抱歉问什么似乎是这样一个简单的问题,一次又一次地问。导轨静态图像没有出现

我使用Rails 4.2.3构建了一个小应用程序。一切都在本地工作,所以我想将其部署到AWS与弹性青苗及以下设置:64位Linux的亚马逊2016.03 v2.1.6运行的Ruby 2.3(彪马)

之前,我部署我运行:

rake assets:precompile RAILS_ENV=production 

我然后将这些文件提交到git并使用eb deploy将文件推送到EC2实例上。

一些工作的事情:

  • 当我ssh到该实例,我看到所有的预编译的资产在/ var /应用/电流/公/资产
  • CSS一切看起来正确的
  • Coffeescripts正在正常运行

但是,静态图像或通过回形针上传的静态图像都没有出现,正如我所期望的。

在production.rb我有这样一行:

config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 

我可以证实,关键是不是在我的ENV变量通过进入控制台:

irb(main):001:0> ENV['RAILS_SERVE_STATIC_FILES'] 
=> nil 

这使我相信,这些文件的服务应该由nginx处理。我可以确认nginx正在运行,但坦率地说,我不知道它是如何配置的。

[[email protected] assets]$ ps waux | grep nginx 
root  2800 0.0 0.4 109364 4192 ?  Ss Oct08 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf 
nginx  2801 0.0 0.6 109820 6672 ?  S Oct08 0:09 nginx: worker process 
ec2-user 21321 0.0 0.2 110456 2092 pts/0 S+ 23:02 0:00 grep --color=auto nginx 

我“觉得”我应该修改我的.ebextensions文件来自动做几件事情,当我部署,但这就是我被困在那里。有什么建议么?

/etc/nginx/nginx.conf

# For more information on configuration, see: 
# * Official English Documentation: http://nginx.org/en/docs/ 
# * Official Russian Documentation: http://nginx.org/ru/docs/ 

user nginx; 
worker_processes auto; 
error_log /var/log/nginx/error.log; 
pid /var/run/nginx.pid; 

events { 
    worker_connections 1024; 
} 

http { 
    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log /var/log/nginx/access.log main; 

    sendfile   on; 
    tcp_nopush   on; 
    tcp_nodelay   on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 

    include    /etc/nginx/mime.types; 
    default_type  application/octet-stream; 

    # Load modular configuration files from the /etc/nginx/conf.d directory. 
    # See http://nginx.org/en/docs/ngx_core_module.html#include 
    # for more information. 
    include /etc/nginx/conf.d/*.conf; 

    index index.html index.htm; 

    server { 
     listen  80 ; 
     listen  [::]:80 ; 
     server_name localhost; 
     root   /usr/share/nginx/html; 

     # Load configuration files for the default server block. 
     include /etc/nginx/default.d/*.conf; 

     location/{ 
     } 

     # redirect server error pages to the static page /40x.html 
     # 
     error_page 404 /404.html; 
      location = /40x.html { 
     } 

     # redirect server error pages to the static page /50x.html 
     # 
     error_page 500 502 503 504 /50x.html; 
      location = /50x.html { 
     } 

     # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
     # 
     #location ~ \.php$ { 
     # proxy_pass http://127.0.0.1; 
     #} 

     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
     # 
     #location ~ \.php$ { 
     # root   html; 
     # fastcgi_pass 127.0.0.1:9000; 
     # fastcgi_index index.php; 
     # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
     # include  fastcgi_params; 
     #} 

     # deny access to .htaccess files, if Apache's document root 
     # concurs with nginx's one 
     # 
     #location ~ /\.ht { 
     # deny all; 
     #} 
    } 

# Settings for a TLS enabled server. 
# 
# server { 
#  listen  443 ssl; 
#  listen  [::]:443 ssl; 
#  server_name localhost; 
#  root   /usr/share/nginx/html; 
# 
#  ssl_certificate "/etc/pki/nginx/server.crt"; 
#  ssl_certificate_key "/etc/pki/nginx/private/server.key"; 
#  # It is *strongly* recommended to generate unique DH parameters 
#  # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048 
#  #ssl_dhparam "/etc/pki/nginx/dhparams.pem"; 
#  ssl_session_cache shared:SSL:1m; 
#  ssl_session_timeout 10m; 
#  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
#  ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP; 
#  ssl_prefer_server_ciphers on; 
# 
#  # Load configuration files for the default server block. 
#  include /etc/nginx/default.d/*.conf; 
# 
#  location/{ 
#  } 
# 
#  error_page 404 /404.html; 
#   location = /40x.html { 
#  } 
# 
#  error_page 500 502 503 504 /50x.html; 
#   location = /50x.html { 
#  } 
# } 

} 

/etc/nginx/conf.d/virtual.conf

# 
# A virtual host using mix of IP-, name-, and port-based configuration 
# 

#server { 
# listen  8000; 
# listen  somename:8080; 
# server_name somename alias another.alias; 

# location/{ 
#  root html; 
#  index index.html index.htm; 
# } 
#} 

的/ etc/nginx的/ CONF。 d/webapp_healthd.conf

upstream my_app { 
    server unix:///var/run/puma/my_app.sock; 
} 

log_format healthd '$msec"$uri"' 
       '$status"$request_time"$upstream_response_time"' 
       '$http_x_forwarded_for'; 

server { 
    listen 80; 
    server_name _ localhost; # need to listen to localhost for worker tier 

    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") { 
    set $year $1; 
    set $month $2; 
    set $day $3; 
    set $hour $4; 
    } 

    access_log /var/log/nginx/access.log main; 
    access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd; 

    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 { 
    alias /var/app/current/public/assets; 
    gzip_static on; 
    gzip on; 
    expires max; 
    add_header Cache-Control public; 
    } 

    location /public { 
    alias /var/app/current/public; 
    gzip_static on; 
    gzip on; 
    expires max; 
    add_header Cache-Control public; 
    } 
} 
+0

请出示在网站致力于nginx的主机配置站点启用 – num8er

+0

我刚才添加的/ etc /nginx/nginx.conf文章末尾。如果这不是您要查找的内容,请告知您的位置。 –

+0

这不是什么检查/etc/nginx/conf.d/中有服务器{}指令的文件,你的问题是nginx不服务器你的静态文件夹或可能看错路径。 – num8er

回答

2

修复webapp_healthd.conf使nginx的在public文件夹中的文件服务解决,如果不能或不存在,则proxy_pass到您的应用程序:

upstream my_app { 
    server unix:///var/run/puma/my_app.sock; 
} 

server { 
    listen 80; 
    server_name _; # need to listen to localhost for worker tier 

    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") { 
    set $year $1; 
    set $month $2; 
    set $day $3; 
    set $hour $4; 
    } 

    access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd; 

    index index.html index.htm; 

    location @app { 
     log_not_found off; 
     access_log off; 
     proxy_pass http://my_app; # proxy passing to upstream 
     proxy_http_version 1.1; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header Host $host; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection 'upgrade'; 
     proxy_cache_bypass $http_upgrade; 
    } 

    root /var/app/current/public; 

    location/{ 
     try_files $uri $uri/ @app; # tries to serve static files if not will ask @app 
    } 
} 
+0

sudo服务nginx停止/ sudo vi webapp_healthd.conf/sudo服务nginx启动 –

+0

启动nginx:nginx:[警告]冲突的服务器名称“localhost”在0.0.0.0:80,被忽略 –

+0

现在一切都是空白的: ) –