[RUBY] Possibility when deploying to EC2 but nothing is displayed in the error log

environment

Ruby 2.5.1 Rails 5.2.4.3

I finished the process of deploying to AWS by referring to the article here, but when I accessed it from a browser, it failed with "Cannot connect to this site". I will ...

(Note) The article I referred to is very easy to understand and is not the fault of the article.

Let's check the log referring to the article to see what is wrong.

Server environment(/var/www/rails/app name/)


cd log
tail -n 30 production.log
スクリーンショット 2020-06-26 16.18.13.png

For some reason, I can't find anything like an error in the log. It didn't make sense at first, but after a while I thought I might not be able to access it from my browser.

So I will try to access http directly using curl.

$ curl -IXGET http://IP address/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.2
Date: Sat, 27 Jun 2020 05:09:57 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Location: https://IP address/

301 is returned. Apparently, access to http has been redirected to https without permission. I dared to access https with curl.

$ curl -IXGET https://IP address/
curl: (7)Failed to connect to IP address port 443: Connection refused

I was angry that 433 ports were not available. Certainly, the security group has not set 433, so it is natural.

So I added 433 to the inbound rule of the security group, and when I accessed it with http from a browser, the page opened with https! (Impressive)

However, the original goal now is to open it with http instead of https ...

result

The cause of the redirect from http to https was the following description in /config/environments/production.rb.

/config/environments/production.rb


config.force_ssl = true

It seems that this was written when it was made ssl with heroku deployment before ... With this, it seems to redirect to https for ssl conversion.

So you can fix it locally, but it is troublesome to push or clone, so for the time being, rewrite the description in the server and just check it.

$ cd /var/www/rails/Ticket-Rec/config/environments/
$ vi production.rb

Changed as follows

/config/environments/production.rb


config.force_ssl = false

Restart unicorn

$ ps -ef | grep unicorn | grep -v grep
hiroki 2031 1 0 June 26?      00:00:02 unicorn_rails master -c /var/www/rails/Ticket-Rec/config/unicorn.conf.rb -D -E production
hiroki 2036 2031 0 June 26?      00:00:00 unicorn_rails worker[0] -c /var/www/rails/Ticket-Rec/config/unicorn.conf.rb -D -E production
hiroki 2038 2031 0 June 26?      00:00:00 unicorn_rails worker[1] -c /var/www/rails/Ticket-Rec/config/unicorn.conf.rb -D -E production

$ kill 2031
$ bundle exec unicorn_rails -c /var/www/rails/Ticket-Rec/config/unicorn.conf.rb -D -E production

Restart nginx

$ sudo service nginx restart

When I accessed http with curl again, 200 was returned!

$ curl -IXGET http://IP address/
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sat, 27 Jun 2020 05:27:46 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: strict-origin-when-cross-origin
ETag: W/"03411acbf679047381b99fd0eda2307c"
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: _myapp_session=%2Fj%2FMy4fzeeSRY3imIh%2FCkJg94SzoshjfdaYZhZcEzF4i%2BxXXUZiYY8M%2Flre%2F6TAAvXqfyrr5sJ8ke2aOlhh4o8i6xsMfO7Ubp7LvUQnAxB9gm%2FbQ8Gc%2BLPzZAxcL9OgDLvQaocLN1MTSz6XKaDM%3D--1h9%2FJNHiHiktaWNU--CJuK9RUucx3dkTVkQpjYLg%3D%3D; path=/; HttpOnly
X-Request-Id: 9d2ee01e-fa05-40ae-8959-6e9b40f9b3e1
X-Runtime: 0.005877

Actually open it in the browser

browser


http://IP address/

I was able to access the app safely! Congratulations!

However, if you make it ssl after this, after all

/config/environments/production.rb


config.force_ssl = true

It seems to be set to lol

However, I found out the reason why it was not connected.

reference

[Carefully explained with images] How to upload Rails application to AWS (EC2) from scratch [Part 1 ~ Network, RDS environment setting ~]

Recommended Posts

Possibility when deploying to EC2 but nothing is displayed in the error log
When the project is not displayed in eclipse
Error when deploying EC2
[Error] The app is not displayed in the production environment
What to do when "Fail to load the JNI shared library" is displayed in Eclipse
When there is no output to stdout in docker log
Error when deploying EC2 on CircleCI
How to output the value when there is an array in the array
How to solve the unknown error when using slf4j in Java
How to write the view when Vue is introduced in Rails?
It should be the same as the sample when logging in to Twitter, but an error occurs ~ resolution
[Rails] About the error that the image is not displayed in the production environment
Error when the member of Entity class used in SpringWebFlux is final
I want to display an error message when registering in the database
What to do if Operation not permitted is displayed when you execute a command in the terminal
[Ruby] How to prevent errors when nil is included in the operation
[Rails] What to do when the Refile image is not displayed when writing the processing at the time of Routing Error
How to resolve the error'ActionView :: Template :: Error (The asset "application.css" is not present in the asset pipeline.'" When precompiling Rails assets
[Ruby] Meaning of &. How to avoid the error when the receiver (object) is nil
[Heroku] How to solve when an error is displayed on git push heroku master
How to set when "The constructor Empty () is not visible" occurs in junit
When the server fails to start in Eclipse
The devise error message is not displayed properly.
When deploying to Heroku, OpenApp causes an error
How to log in automatically when Ubuntu restarts
[Java] Something is displayed as "-0.0" in the output
How to set the log level to be displayed in the release version of orhanobut / logger
What to do when Address already in use is displayed after executing rails s
A warning is displayed when trying to use a huge integer with the special variables $ 1, $ 2, $ 3 ...
When the hover of Eclipse is hard to see
I want to embed any TraceId in the log
No error message is displayed when create action fails
How to perform a specific process when the back button is pressed in Android Fragment
How to solve the problem when the value is not sent when the form is disabled in rails and sent
[Rails] What to do when the view collapses when a message is displayed with the errors method
I want to set the conditions to be displayed in collection_check_boxes
How to set chrony when the time shifts in CentOS7
What to do if FacesMessage is set but not displayed
Error in production environment (The asset "~" is not present in the asset pipeline.)
The idea of cutting off when the error is not resolved
When [command not found: composer] is displayed when [composer install] is displayed in Laravel
A validation error occurred when saving to the intermediate table.
An error occurs when codedeploy-agent is installed in Ubuntu Server 20.04
How to get the log when install4j does not start
Behavior when each is executed in the reverse order Range
Logback log is not output when the server application is closed
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate
Monkey patch to return the current time when an empty string is specified in Ruby's Time.parse
[Programming beginner] What to do when rails s becomes an error in the local development environment
How to solve the problem that the website image is not displayed after deploying to heroku on Rails 5
Settings to be made when HTML or JSP is formatted in Eclipse and the layout is disappointing
Throw an exception and catch when there is no handler corresponding to the path in spring
What to do when you want to know the source position where the method is defined in binding.pry
I want to make the frame of the text box red when there is an input error
About the solution to the problem that the log of logback is not output when the web application is stopped
Static function to check if the RGB error of BufferdImage is within the specified ratio in Java
What to do when javax.el.ELException: Not a Valid Method Expression: appears when the JSF screen is displayed