LoginSignup
2
2

More than 5 years have passed since last update.

Elastic Beanstalkでnginx_statusを設定

Posted at

What

SolutionStack: 64bit Amazon Linux 2016.03 v2.1.3 running Ruby 2.3 (Puma)の場合

Where

nginx用の設定はファイルは/etc/nginx/conf.d/webapp_healthd.confだけど、こいつはsymlinkなので、実体は/opt/elasticbeanstalk/support/conf/webapp_healthd.conf

How

.ebextensionsを使う

.ebextensions/nginx.config
commands:
  01_nginx_status:
    command: |
      sed -i -e ':loop; N; $!b loop; ;s/r healthd;\n\n  location \/ {/r healthd;\n\n  location  \/nginx_status {\n    stub_status on;\n    access_log off;\n    allow 127.0.0.1;\n    deny all;\n  }\n\n  location \/ {/g' /opt/elasticbeanstalk/support/conf/webapp_healthd.conf

これが

/opt/elasticbeanstalk/support/conf/webapp_healthd.conf
  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;
  }

こうなる

/opt/elasticbeanstalk/support/conf/webapp_healthd.conf
  access_log  /var/log/nginx/access.log  main;
  access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;

  location  /nginx_status 
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
  }

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

ある程度冪等性を考慮してるので、毎回実行されても問題ない。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2