Strange unknown POST request repeatly to Rails app - ruby-on-rails

I have my app run in production mode recently and realize in production.log that there are so many POST '/' request to my app URL. From the production.log files, I see that those POST requests come every 2 minutes.
The error in the log file looks like this...
F, [2019-09-10T19:45:13.948722 #28016] FATAL -- : [d0a8aada-89cf-495c-b7ae-c996ca3b7595]
[d0a8aada-89cf-495c-b7ae-c996ca3b7595] ActionController::RoutingError (No route matches [POST] "/"):
My Rails app run on Ubuntu 18 and using Nginx + Passenger.
I try find way to block suspicious IP by look into /var/log/ngix but I can't find the IP that associated to POST request. I think I miss something big.
Could you help suggest if where should I inspect to get the source of those requested POST ? Any suggestion is very appreciate, thank you.

Related

Heroku app page not found

I deployed a rails app on Heroku. Everything was working fine. I pushed the code to Heroku master, and everything worked as expected. I also ran Heroku run rails db:migrate. No errors were thrown. I can even run the Heroku run rails console, and create objects, no problem. However, It does tell me that I have to type in User.connection, (Users are the only models I have in the app right now). When I type Heroku config I get expected output. Everything seems perfect. But, when I open the app, it says that the page is not found:
No webpage was found for the web address: https://my-api.herokuapp.com/
It's probably worth mentioning that It's a rails API, therefore, there are no views, and no root page. But despite that, I still don't get any responses when I make API calls with Postman. I simply get a 404 response. I would at least imagine that HTTP requests would work, but they don't. Any idea why?
Upon loading the app the logs say
ActionController::RoutingError (No route matches [GET] "/"):
does mean there is no root route? I thought for an API, there didn't need to be one?
ActionController::RoutingError (No route matches [GET] "/"):
It means that it is pointing to your app and search for root route but if that isn't defined in the routes file then it will show this error.
For API mode only means that it will not generate css and coffee files related to controllers.
Open App links to app and finds the root path and if it doesn't find then it this error occur.
Since you are using API mode thus this error will not be troublesome.
Check your routes.
Heroku can return such an answer when you just have no a root route.
If you have any specific routes you can try to go it and application will work.
https://my-api.herokuapp.com/return_mystuff

Routing error on ch 2 micropost rails tutorial (routing_error.html.erb within rescues/layout)

I'm working on the micropost toy_app in Chapter 2 of the Ruby on Rails Tutorial, and my site on the cloud9 url (http://rails-tutorial-[username].c9users.io/microposts/new) isn't working. I've tried a bunch of things to try to fix this (eg, ctrl c, starting rails server over, ctrl c again, pushing possible changes I missed to heroku etc), but the displayed web page toggles between the red and white "we're sorry but something went wrong" generic error and the blue/pink floral "No application seems to be running here! Cloud9 can't get you to your requested workspace" errors.
In the C9 dev logs show these two error over and over:
Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/routing_error.html.erb within rescues/layout
and
ActionController::RoutingError (uninitialized constant MicropostsController)
I've searched all over and it looks like most people with routing errors have different errors messages, and it's because they haven't defined their routes properly. I'm totally new to this, and I can't figure out what I'm doing wrong.
Previously (when I went through chapter 1 of the tutorial), my /users and /users/new pages worked, however now none of those URLs work either. Would this be related to a C9<>bitbucket<>heroku issue, or is it likely to be with my actual code? heroku logs didn't show anything meaningful.
My routes.rb file looks like this:
Rails.application.routes.draw do
resources :microposts
resources :users
root 'microposts#index'
end
For what it's worth, I started the tutorial on 12/25/15, which is the day that rails 2.3 was released-- however my logs show I'm on 2.2.1. I wonder if during the 20-30 hours since I started on 12/25, my rails version on c9 got outdated? I don't understand how that works since I'm using a cloud IDE.
I'm brand new to rails and haven't done any programming aside from a few classes in college-- any tips or pointers would be appreciated.
After starting over, I finally figured it out after another hour or so-- I had 2 problems. The first was that I'd only run one of the 2 necessary scaffolding commands in the tutorial (doh!). I discovered this by more carefully reading the c9 development log, and noticed a line that said ActionController::RoutingError (No route matches [GET] "/micropost"):. at this point I realized I was missing the micropost application controller, because I'd never created it with the 2nd scaffolding command: rails generate scaffold Micropost content:text user_id:integer
The other problem is that I didn't (and still don't) really understand how the rails server works-- so I was making my changes and not realizing that the server needed to be actively running for the website to load. When I run the rails server -b $IP -p $PORT command, it looks like it never finishes (eg, the $ for me to start my next command prompt never appears until I hit ctrl c). So I kept hitting ctrl c, not realizing I was killing the server that was hosting the web page.
What I did now was make all my changes, then run the server, then hit ctrl c when I need to make more changes.
Am I doing something wrong with the server stuff? Overall it's working, but it seems like there could be a better way.

Rails + Passenger removing controller name

I have picked up a legacy Rails app that uses Apache + Passenger.
The app has no documentation for me to work with.
When I run the application and hit a URL like so:
http://app.local:3000/groups/group-name
It will hit the show action in the groups controller. However when I run the app on Apache + Passenger and hit the same URL:
http://app.local/groups/group-name
It will actually tries to load the following URL:
http://app.local/group-name
From the log it has this:
Started GET "/groups/group-name" for 127.0.0.1 at 2012-12-19 03:28:44
+0000
ActionController::RoutingError (No route matches "/group-name"):
It is a total long shot and sorry to not provide anymore information but does anyone know why this would be happening and any suggestions of where to look?
I have checked the http.conf and it has no rewrite rules or anything. Just a standard http.conf for Passenger + Rails.
Any help or suggestions would be appreciated.
Thanks
Tony

Rails Routing Broken In Production - Caching of routes.rb suspected

Update: Turns out that this problem was because half my mongrel did not restart. Thanks all for help!
Hi folks, i have an urgent problem. Essentially, my routing works on my localhost. But when i deployed this to production, the routes does not seem to work correctly.
For example, given a new route "/invites" - sometimes i will get a 404, and sometimes it will work correctly.
I suspect there is some caching going on somewhere, but i am not sure.
Logs: when a page is not found (when the routes are supposed to be accurate)
Processing UsersController#network
(for 67.180.78.126 at 2010-06-01
09:59:31) [GET] Parameters:
{"id"=>"new"}
ActionController::RoutingError (No
route matches
"/comm/role_playing_games" with {}):
app/controllers/application_controller.rb:383:in
prev_page_label'
app/controllers/application_controller.rb:238:in
log_timed_info'
app/controllers/users_controller.rb:155:in
network'
app/controllers/users_controller.rb:151:in
network'
app/controllers/application_controller.rb:44:in
turn_on_query_caching'
app/controllers/application_controller.rb:43:in
turn_on_query_caching'
app/controllers/application_controller.rb:42:in
turn_on_query_caching'
app/controllers/application_controller.rb:41:in
turn_on_query_caching'
app/controllers/application_controller.rb:40:in
turn_on_query_caching'
app/controllers/application_controller.rb:39:in
turn_on_query_caching' haml (3.0.6)
lib/sass/plugin/rack.rb:41:in `call'
Rendering
/mnt/app/releases/20100524233313/public/404.html
(404 Not Found)
From the little you have posted, this definitely isn't a caching or routing problem.
It sounds like you are trying to generate a link to the previous page the person was on inside ApplicationController and you have a bug with it. You will have to post the relevant code from application_controller.rb.
Did you make sure you restarted your server (like apache, ngix or passenger)?
Also, sometimes a browser can cache urls, just close your browser and reopen it, see if that fixes it.
Also, once in a blue moon, I'll forget to push the code to GIT and therefore production server doesn't get the latest code. Just check that your server actually has the code there.

Routes not resolving in Production Environment (Rails 2.3.5)

I'm deploying my app to a live server running passenger on Apache. I've tested the app locally and my routes appear sound. I have my public controllers under app/controllers/content and my admin controllers under app/controllers/admin.
Despite everything working in the development environment i'm getting "The page you were looking for doesn't exist." error when I request http://mydomain.com/content/compare. (i.e. Content::CompareController#index).
My production log contains the lines:
Processing ContentController#compare (for 86.40.236.34 at 2010-08-14 15:03:15) [GET]
Authentication: session found, user_id is set
ActionController::UnknownAction (No action responded to compare. Actions: ):
I've called rs.recognize_path 'content/compare' and I get the error:
ActionController::RoutingError: No route matches "content/compare" with {}
The same command works with my development machine however. I've tried adding the line
map.connect 'content/:controller/:action' to the routes config file but this doesn't have any effect and I don't think it would be useful in the long run either.
Any advice on this? Seems strange that there are inconsistences between the Rails Environments.
Thanks in advance for any help,
Can we see your routes.rb file?
It appears that on your production machine it is trying to call the compare method in ContentController. Is this the method you want to be calling or is it index?
My guess is there is something wrong in your routes file. You can compare it on both environments by running rake routes.

Resources