apache2 + Passenger3 + Rails3 routing problem - ruby-on-rails-3

Having a problem with passenger 3
in routes.rb i have
match 'main/subgroups/:id' => 'main#subgroups'
And in access_log file
"GET /main/subgroups/Arts HTTP/1.1" 304 - "-"
"GET /main/subgroups/Arts%2FCrafts%2FNeedlework HTTP/1.1" 404 323 "-"
As I understand Apache does not pass the second request to passenger.
What should I change in httpd.conf?

The problem is that the second URL is not matching the route since your 'id' field has forward slashes in it, which is a delimiter for rails routes.
In order to make this work try changing your route to (Note the * instead of the : on id):
match 'main/subgroups/*id' => 'main#subgroups'
That should ensure that everything after main/subgroups is set into params[:id] regardless of it's contents.

Related

Configure Apache to pass the hash character to CGI scripts as part of QUERY_STRING

I am working on emulating an embedded device that is being controlled via HTML commands. The controller issues URLs such as
http://192.168.0.10/cgi-bin/aw_cam?cmd=QFT&res=1
And these affect the device in specific ways. My goal is to make an emulator of the device so I need to capture and handle all such requests. I have successfully configured Apache to call my scripts and I can get access to the "cmd=QFT&res=1" control string by reading the value of QUERY_STRING. I am using Apache 2.4.18 on Ubuntu 16.04.5. The scripts are written in C++.
The problem I am running into is that some of the commands issued by the controller are of the following form:
http://192.168.0.10/cgi-bin/aw_ptz?cmd=#P80&res=1
http://192.168.0.10/cgi-bin/aw_ptz?cmd=#T50&res=1
For whatever reason, whoever designed the command structure decided to use the # character as part of the command. But since the '#' delimits the fragment part of the URL, the information after it never makes it to my script, which only receives "cmd="
Is there any way to force Apache to pass the entire string after the ? to my scripts? I cannot change the client or the protocol, only the server side.
Edit:
The apache log shows the entire URL (see portion of log file below), so even though # is supposed to be a fragment delimiter, it makes it into the log file at least but not the cgi script.
192.168.0.9 - - [27/Jan/2019:00:21:10 +0000] "GET /cgi-bin/aw_ptz?cmd=#P53&res=1 HTTP/1.0" 200 151 "-" "-"
192.168.0.9 - - [27/Jan/2019:00:21:11 +0000] "GET /cgi-bin/aw_ptz?cmd=#P66&res=1 HTTP/1.0" 200 151 "-" "-"
192.168.0.9 - - [27/Jan/2019:00:21:11 +0000] "GET /cgi-bin/aw_ptz?cmd=#P99&res=1 HTTP/1.0" 200 151 "-" "-"
192.168.0.9 - - [27/Jan/2019:00:21:11 +0000] "GET /cgi-bin/aw_ptz?cmd=#P76&res=1 HTTP/1.0" 200 151 "-" "-"
This seems to work:
RewriteCond %{THE_REQUEST} \s(.*)#(.*)\s
RewriteRule ^ http://localhost:8000%1#%2 [P,NE]
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
(I had python simple http server listening on localhost:8000 to verify if hash was passed correctly

Googlebot-Image/1.0 requesting multiple images

for a while I experienced that the google image bot is requesting a bunch of images in a single request. This request always ends up in a 404, but all images exist.
The request url consists a comma seperated list of URLs.
Here is a line from the apache access.log:
66.249.76.96 - - [21/Nov/2018:15:25:14 +0100] "GET /images/img1.jpg,https://example.com/images/img2.jpg,https://example.com/images/img3.jpg HTTP/1.1" 404 10459 "-" "Googlebot-Image/1.0"
Is this request type even possible? And how can I fix the server to serve the images?
Thanks in advance.

Combine www and non-www in Kibana

I setup an ELK stack in AWS Elasticsearch. I'm ingesting Apache logs into ELK, one of the apache fields is the vhost. In the vhost field it will have www.domain.com and domain.com, I'd like to combine those so I can setup accurate searches and visualize data by vhost. Currently it separates www.domain.com and domain.com as separate values.
123.456.7.89 - - [13/Feb/2017:18:56:19 +0000] thisdomain.com "GET /about.html HTTP/1.0" 200 1446 "-" "-" Server=aws8 SSL=- 634713 0
123.456.7.89 - - [13/Feb/2017:18:58:19 +0000] www.thisdomain.com "GET /services.html HTTP/1.0" 200 1446 "-" "-" Server=aws8 SSL=- 634713 0
I entered this data into Elasticsearch setup in AWS which gave me my field definitions. Also works in Cloudwatch.
[ip, user, username, timestamp, vhost, request, status_code, bytes, referrer, browser, server, ssl, timems, times]

Apache 500 Error due to User Agent?

I am currently getting 500 errors from Apache using a alarming probe shell script that has been provided to myself.
Unfortunately I have not been able to get to the bottom of why the script generates a 500 error when attempting to access content locally on the server but using other methods like wget and telnet works fine.
The following are the Apache access log entries for each of the attempts:
Using Wget
127.0.0.1 - "" [19/Mar/2013:14:31:44 +1100] "GET /index.html HTTP/1.1" 200 1635 "-" "Wget/1.13.3" "-"
Using Telnet
127.0.0.1 - "" [20/Mar/2013:13:12:11 +1100] "GET /index.html HTTP/1.1" 200 1635 "-" "-" "-"
Using the Probe Scripts
127.0.0.1 - - [19/Mar/2013:14:33:56 +1100] "GET /index.html HTTP/1.1" 500 - "-" "" "-"
The only difference I can see is that the probe has a - instead of a "" in the user agent (3rd item) which either way tells me it wasn't passed in any of the instances (as this is expected since there is no authentication).
I've bumped up the logging for everything in Apache and can't figure out what is amiss. There is no processing involved, it's a static file, and I have attempted with other file types too, like images to no avail.
Does anyone have any ideas or has seen something similar?
Thanks,
Tony

RedirectMatch don't work

I want to tell to my Apache that i want a redirect permanent rules.
I have theses 2 kinds of hits in my logs:
xx.xxx.xx.x - - [15/Mar/2013:08:14:21 +0100] "POST /oldEndPoint/services/toto HTTP/1.1" 200 - 6003 -
xx.xxx.xx.x - - [15/Mar/2013:08:15:40 +0100] "POST /newEndPoint/services/Tutu/toto HTTP/1.1" 200 - 1316 -
I want to tell to Apache, when he receive hits to /oldEndPoint/services/toto then he should do a redirect permanent (301) to the new url: /newEndPoint/services/Tutu/toto.
I have tried with this rule, but it's don't work, no redirect appear:
RedirectMatch 301 /modBackend/moderation/facebook /modFront/services/Moderation/facebook
Thanks!
You don't need RedirectMatch for simple redirects.
See just Redirect instead. You must give the old URL first and the new one last
Redirect /oldEndPoint/services/toto /newEndPoint/services/Tutu/toto