[RAILS] [Beginner] Commands and knowledge that may be useful for error resolution when deploying AWS

background

I suffered from a lot of errors when deploying to AWS, so I decided to put it together in an article. I hope it helps beginners like me!


Constitution

I myself deployed using Ruby on Rails, VPC / EC2 (Nginx, Unicorn) / RDS (PostgreSQL) / Route53 / ALB. Articles referred to when deploying https://qiita.com/naoki_mochizuki/items/f795fe3e661a3349a7ce https://qiita.com/Yuki_Nagaoka/items/1f0b814e52e603613556


Common

You can check the process by using the ps command. Articles that referred to the ps command https://eng-entrance.com/linux-command-ps

$ ps -x            #Command to check the currently running process

Application related

When the application you are deploying displays we're sorry, but something went wrong.. Check if there is a problem with the app

Server environment/var/www/rails/app name


$ cd log
$ tail -n 30 production.log

If there is a description of the error, there is a problem with the application. If there is no particular error, there is a high possibility that there is a problem with the web server settings and the deployment has not been successful.


nginx related

・ Check if nginx is running

Server environment


$ sudo systemctl status nginx

ʻActive: active (running) If it is displayed as `, it is running.

-Restart command

Server environment


$ sudo service nginx restart

-Check if there is an error in the nginx file

Server environment


$ sudo nginx -t

This is a convenient command that tells you where the error is if there is an error. If there is no problem with the nginx file, it will be displayed like this. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful


Unicorn related

A command to check Unicorn logs. I think a common error is ʻAlready running on PID: (process number)`, which occurs when there are unwanted processes left.

Server environment/App directory


$ cat log/unicorn.log -n

Unicorn process confirmation command

Server environment


$ ps -ef | grep unicorn | grep -v grep

Command to terminate Unicorn process When the error of ʻAlready running on PID: (process number)` occurs, I think that the error can be solved by deleting unnecessary processes with this command.

Server environment


$ kill (Process number)

PostgreSQL related

Command to check if PostgreSQL is running If it says Active: active (running), it is running.

Server environment


$ systemctl status postgresql.service

Start PostgreSQL

Server environment


$ sudo systemctl enable postgresql
$ sudo systemctl start postgresql

Other

Google Chrome, http related

When I accessed the application deployed with Google Chrome, I forcibly accessed https (when https conversion was not implemented) and the application did not open. The solution was to delete the history data by checking Chrome history → Delete browsing history data → Cached images and files.

You can check the response with the following command. If the web server file is error-free and the curl command returns a solid response, but redirects to https, this may be the problem.

$ curl http://example.com   #http://example.com is the domain of the app.

Also, when connecting via http Must be config.force_ssl = false.

config/environment/production.rb


$ config.force_ssl = false 

https conversion

At first, I thought about making it https by editing the file on the web server, but I knew that it would be easier to make it https using the service called ALB on AWS, so I used ALB. If you are a beginner and have trouble converting to https, I personally recommend using ALB. You can use ALB to redirect http requests to https.

[Articles used as a reference for https conversion] https://aws.amazon.com/jp/premiumsupport/knowledge-center/elb-redirect-http-to-https-using-alb/ https://dev.classmethod.jp/articles/alb-redirects/ In addition to this, if you search for "ALB https redirect", you will find many useful articles!

Recommended Posts

[Beginner] Commands and knowledge that may be useful for error resolution when deploying AWS
Tools and commands that may be useful for Java troubleshooting
[Beginner] Commands and knowledge that may be useful for error resolution when deploying AWS
[For beginners] Let's be able to coat like Swift!
Tools and commands that may be useful for Java troubleshooting
[Rails] About error resolution when installing devise and activeadmin
Causes and remedies for the exception "ServletException: Error instantiating servlet class" when deploying Java applications