Пустая страница nginx с puma и rails на beanstalk

Я попытался развернуть rails api для эластичного beanstalk с nginx и puma в качестве сервера приложений. Развертывание прошло успешно, база данных создана и перенесена.

Однако при доступе в Интернет отображается только белая страница.

Я вижу, что запрос был записан в журнал доступа nginx, однако он не записан в журнал puma.

Далее следует nginx conf:

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

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

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;
    #}
}

Conf использует директивы include, которые имеют следующее содержимое: upstream my_app { сервер 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
задан 16 April 2018 в 10:15
1 ответ

Проверьте файл журналов, возможно, nginx настроен неправильно, если это так, вы можете обратиться к этим сообщениям для решения ( https://stackoverflow.com/questions/49360715/elastic- beanstalk-customize-puma-configuration ) ( https://stackoverflow.com/questions/40938155/right-way-to-deploy-rails-puma-postgres-app-to-elastic-beanstalk ). В основном вам нужно использовать ssh в своем экземпляре и настроить файл конфигурации nginx, хранящийся в /etc/nginx/nginx.conf, вам нужно привязать там сервер puma к сокету unix, и он соединяется с NGINX. Пример файла конфигурации NGINX:

user  root;

error_log  /var/log/app-nginx-error.log;
pid        /var/run/app-nginx.pid;

events {
    worker_connections  8096;
    multi_accept        on;
    use                 epoll;
}

http {
    ....

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

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

    .... 
}

Важная часть, которую вы должны добавить в файл конфигурации NGINX:

upstream appserver {
  server unix:///var/run/puma.sock;
}
0
ответ дан 5 December 2019 в 06:10

Теги

Похожие вопросы