Skip to content

Instantly share code, notes, and snippets.

@mikaelbalin
Last active December 15, 2019 08:49
Show Gist options
  • Save mikaelbalin/1c657178f9c21184d99e19a9184913f7 to your computer and use it in GitHub Desktop.
Save mikaelbalin/1c657178f9c21184d99e19a9184913f7 to your computer and use it in GitHub Desktop.
Connect to AWS instase made by Elastic Beanstalk and add custom error page

Подключение к серверу через терминал

Нужно отредактировать Security Group и разрешить доступ:

  • Добавить правило для inbound rules - SSH для вашего IP, например 78.25.122.95/32

Сделать Key Pair:

  • Сделать Key Pair, например под названием oregon-key-pair.pem
  • В Elastic Beanstalk зайти в Configuration, потом Instances и выбрать созданную EC2 key pair

Для того, чтобы убелиться, что ключ не виден публично, использовать команду (если знаете, что это значит, пожалуйста напиши в комментарий на эту тему):

chmod 400 my-key-pair.pem

Для подключения к инстансу надо набрать команду ssh, указать путь к ключу, указать имя пользователя (ec2-user для Amazon Linux) и публичный DNS:

ssh -i my-key-pair.pem [email protected]

Изменить файл ssh_config через sudo nano _etc_ssh/ssh_config на строчках 30 и 31:

GSSAPIKeyExchange no
GSSAPITrustDNS no

Если нужно отправить файл:

$ scp -ri my-key-pair.pem /path/example [email protected]:~

Для пересылки файлов больше чем 2Mb нужно найти строчку upload_max_filesize в файле /etc/php.ini с помощью Control + w и поменять значение например на 6M.

Страница с ошибками

Файлы сайта хранятся в var_app_current и /var_www_html. Чтобы указать путь к персональной странице, сообщающей об ошибках, нужно отредактировать httpd.conf:

sudo nano /etc/httpd/conf/httpd.conf

И внести следующие изменения:

ErrorDocument 404 http://www.websitename.ru/error.php
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorDocument 404 /error.php
</VirtualHost>

В конце можно сделать перезагрузку:

sudo restart httpd

This is the short manual that explains how to connect to Amazon Linux instance run with PHP made automatically by AWS Elastic Beanstalk and get working custom error page for your website.

Это короткое руководство, рассказывающее как подлючиться к серверу на базе Amazon Linux работающую с PHP, созданному автоматически через AWS Elastic Beanstalk и настроить персональную страницу об ошибке для вашего сайта. Русская версия следует сразу за английской.

Connect to instance with terminal

Edit Security Group and provide access:

  • Add rule for inbound rules - SSH for your IP, for example 78.25.122.95/32

Create Key Pair:

  • Create Key Pair, for example oregon-key-pair.pem
  • Enter Elastic Beanstalk Configuration -> Instances and select created EC2 key pair.

Change file ssh_config with sudo nano _etc_ssh/ssh_config on lines 30 and 31:

GSSAPIKeyExchange no
GSSAPITrustDNS no

To make shure that key isn't visible publecly, use command (if you know what that exactly means, please describe in comments):

chmod 400 my-key-pair.pem

To connect to instance use command ssh, then point to the key, provide user name (ec2-user for Amazon Linux) and public DNS:

ssh -i my-key-pair.pem [email protected]

Edit ssh_config with sudo nano _etc_ssh/ssh_config on lines 30 and 31:

GSSAPIKeyExchange no
GSSAPITrustDNS no

If you need to send a file:

$ scp -ri my-key-pair.pem /path/example [email protected]:~

If you need to send a file bigger then 2Mb, find line upload_max_filesize in /etc/php.ini with Control + w and change value for example to 6M.

Error page

Website files located in_var_app_current and /var_www_html_. To provide path to a custom error page, open httpd.conf:

sudo nano /etc/httpd/conf/httpd.conf

And add the following changes:

ErrorDocument 404 http://www.websitename.ru/error.php
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorDocument 404 /error.php
</VirtualHost>

Finally make a restart:

sudo restart httpd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment