0

몇 번 묻는 간단한 질문 인 것처럼 보이는 것에 대해 사과드립니다.레일 고정 이미지가 나타나지 않습니다.

Rails 4.2.3을 사용하여 작은 응용 프로그램을 만들었습니다.

rake assets:precompile RAILS_ENV=production 

I을 : 나는 실행 배포하기 전에 루비 2.3 (푸마)를 실행하는 64 비트 아마존 리눅스 2016.03 v2.1.6

: 나는 다음과 같은 설정을 탄성 콩 줄기와 AWS에 배포하려고 노력하고 있어요 그래서 모든 로컬로 작동 그런 다음이 파일들을 git로 커밋하고 eb deploy를 사용하여 파일을 EC2 인스턴스 위로 밀어 올립니다.

어떤 사물이 작동 : 그 인스턴스에 ssh를 할 때

  • , I는/var 미리 컴파일 된 자산을 모두 볼/응용 프로그램/현재/공공/자산
  • CSS 모두가 올바른
  • Coffeescripts를 찾습니다 제대로 실행되고 있습니다.

그러나 정적 이미지 나 내가 PaperClip을 통해 업로드 한 이미지는 예상대로 표시되지 않습니다.

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

믿고 날 리드 : 그 키가 콘솔로 이동하여 내 ENV 변수에없는 확인할 수

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

: production.rb에서

나는이 라인을 가지고 이 파일들의 서빙은 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가 자동으로 몇 가지를 할 파일을 편집하기로되어 있지만, 내가이 붙어있어 경우에 관하여입니다. 어떤 제안?

# # 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의 /etc/nginx/conf.d/virtual.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/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

사이트를 사용 /nginx/nginx.conf를 게시물 끝에 추가하십시오. 그것이 당신이 찾고있는 것이 아닌 경우, 그 위치에 관해 조언 해주십시오. –

+0

그게 /etc/nginx/conf.d/에 server {} 지시어가있는 파일을 검사하는 것이 아니라면, nginx가 정적 폴더를 서버하지 않거나 잘못된 경로를보고있을 수 있습니다. – num8er

답변

2

수정 webapp_healthd.confpublic 폴더에있는 파일을 봉사의 nginx를 만들거나 존재하지 않는 수없는 경우 다음 앱에 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"on 0.0.0.0:80, 무시한 –

+0

이제 모든 내용이 비어 있습니다.) –