Nginx not serving static content over rails - ruby-on-rails

I want to serve static images with nginx. I have in my nginx.conf
location /i/ {
alias /home/matt/images/;
}
I am going to server.com/i/928675140291b6.jpg Just to see if it will serve the image, But I'm getting in production.log:
ActionController::RoutingError (No route matches [GET] "/i/928675140291b6.jpg"):
The response to curl -I server.com/i/928675140291b6.jpg:
HTTP/1.1 404 Not Found
Server: nginx/1.10.0 (Ubuntu)
Date: Mon, 24 Oct 2016 13:49:50 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 1564
Connection: keep-alive
X-Request-Id: abb0cb6c-e922-4186-b245-e78b21a88919
X-Runtime: 0.007451

My problem was, for some reason, nginx doesen't care about the nginx.conf in my Rails project folder. I edited the file in /etc/nginx/sites-enabled/my_app and now nginx is listening.

Related

How to list repositories/catalog in IBM Container Registery?

I am using IBM Container Registry and trying to list the repositories/catalog using the below command.
curl -i https://us.icr.io/v2/_catalog
HTTP/2 401
content-type: application/json; charset=utf-8
www-authenticate: Bearer realm="https://us.icr.io/oauth/token",service="registry",scope="registry:catalog:*",error="invalid_token"
The www-authenticate field state that the scope of the token should be registry:catalog:*.
When I tried to create a token with this scope, the generated token provides an empty access list.
Running the command with above generated access token gives the below error:
curl -i -H "Authorization: Bearer $token" https://us.icr.io/v2/_catalog
HTTP/2 403
content-type: application/json; charset=utf-8
www-authenticate: Bearer realm="https://us.icr.io/oauth/token",service="registry",scope="registry:catalog:*",error="insufficient_scope"
date: Mon, 23 May 2022 16:53:38 GMT
content-length: 134
cache-control: no-cache, no-store, must-revalidate
content-security-policy: default-src 'self'; frame-ancestors 'none'; form-action 'none';
docker-distribution-api-version: registry/2.0
expires: 0
pragma: no-cache
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff
x-frame-options: DENY
x-registry-supports-signatures: 1
x-xss-protection: 1; mode=block
server: IBM Cloud Container Registry
{"errors":[{"code":"DENIED","message":"insufficient scope","detail":[{"Type":"registry","Class":"","Name":"catalog","Action":"*"}]}]}
Does IBM Container Registry support _catalog docker v2 api?
Are there any other way to list the repositories?
Note: I have tried https://cloud.ibm.com/apidocs/container-registry#list-images, it lists all the images but not the repositories like _catalog docker v2 api.
According to the IBM Cloud Container Registry documentation and the experience you made, that API is not supported.
IBM Cloud Container Registry supports Docker Engine v17.07, or later.
Docker itself defines the Engine API, Hub API and the Registry API. The latter has the function you asked for.

HTTP Request with content-length > 0 but body is empty in docker container

I am trying to run curl commands in a groovy script and containerize it using docker. The script runs a bunch of curl commands. Using the following code to execute the commands.
def process = commandArray.execute()
def out = new StringBuffer()
process.consumeProcessOutputStream(out)
if (process.isAlive()) process.waitForOrKill(240000)
Things work fine when I run locally. But When I execute the groovy script in container the response body comes as empty but the Content-Length will be more than 0.
My headers are as below(Have Replaced few content with dummy data, ex: xyz.com)
* TCP_NODELAY set
* Connected to xyz.com (10.20.30.400) port 80 (#0)
> GET /abc/xyz/type HTTP/1.1
> Host: xyz.com
> User-Agent: curl/7.68.0
> Accept: */*
>
< HTTP/1.1 200 OK
< cache-control: no-cache, private
< etag: "000000000000000000000000000000"
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< strict-transport-security: max-age=31536000 ; includeSubDomains
< x-frame-options: DENY
< content-type: application/json
< content-length: 72950
< date: Tue, 22 Jun 2021 06:17:09 GMT
< x-envoy-upstream-service-time: 57
< server: envoy
<
{ [15940 bytes data]
* Connection #0 to host xyz.com left intact
Although the content-length: 72950 when I print the out object, it is empty []
What might be going on here? This issue is specific to running in container
The curl command looks as below
curl -s -v -L -k -X 'GET' --cert '/tmp/groovy-generated-10305010891926264191-tmpdir/client-cert.pem' --proxy 'https://proxy.com:30000' --noproxy 'localhost,127.0.0.1' 'https://example.com/abc/xyz/type'

Unable to post telemetry data using HTTP from command line

Unable to post telemetry data using HTTP from command line, I can not get any message in my thingsboard Platform
C:\Users\Administrator>curl -v -X POST -d "{\"temperature\": 25}" http://localhost:8080/api/v1/mdULJGYox2jQmDmFbZID/telemetry --header "Content-Type:application/json"
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST /api/v1/mdULJGYox2jQmDmFbZID/telemetry HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Type:application/json
> Content-Length: 19
>
* upload completely sent off: 19 out of 19 bytes
< HTTP/1.1 200
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< Content-Length: 0
< Date: Wed, 15 Jul 2020 07:36:48 GMT
<
* Connection #0 to host localhost left intact
i'm new to thingsboard. I also encountered the same issue right now. But it works when i use postman to send the same http request to a locally installed se. So maybe it gets stuck in the curl command.

Haproxy - Cannot setup the most basic proxy

Please, can somebody look at this config?
global
log stdout format raw local0 debug
stats timeout 30s
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 50000
timeout client 50000
timeout server 50000
frontend app
bind *:15080
default_backend myback
backend myback
server site google.com:80 check
Why is this not working? If I try to visit 127.0.0.1:15080 it takes some time and then the url in a browser changes to www.google.com:16080 which obviously doesn't take you anywhere. The browser says: "This site can’t be reached - ERR_CONNECTION_TIMED_OUT".
So why doesn't it proxy to port 80 as one would expect?
The log entry does not tell much:
127.0.0.1:50871 [01/Jul/2019:14:39:45.879] app myback/site 0/0/20/84/104 301 681 - - ---- 2/2/0/0/0 0/0 "GET / HTTP/1.1"
Haproxy version:
HA-Proxy version 2.0.0-4fb65f-8 2019/06/19 - https://haproxy.org/
EDIT:
I somehow solved the problem by trial & error..
Actually, HAProxy is working as expected and proxying your request to google. Google, however, sees that the host header is 'Host: 127.0.0.1:15080', and responds with a 301 redirect to www.google.com:15080. You can see this without setting up HAProxy by doing:
$ curl -I -H 'Host: 127.0.0.1:15080' google.com
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com:15080/
Content-Type: text/html; charset=UTF-8
Date: Mon, 01 Jul 2019 14:26:09 GMT
Expires: Wed, 31 Jul 2019 14:26:09 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 225
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
If you want to set up a very basic proxy to google, you need to make sure your host header matches and that you are sending requests via https.
backend myback
http-request set-header Host www.google.com
server site google.com:443 ssl verify none check

Response Value Does Not Return After Successfully Login With CURL

I had problem which is I cannot get response value even though sign in into rails app using curl post going through. This is my CURL command:
curl -i -H 'Content-Type: application/json' -X POST http://localhost:3000/users/sign_in -d '{"user": {"email": "admin#admin.com", "password": "abc12345"}}'
and this is http status I got:
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Etag: W/"fa9a29286a105efca890fba3ae3fc084"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: a4ecab97-f7fe-4354-834a-f2ac07faa871
X-Runtime: 0.332680
Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)
Date: Wed, 29 Jul 2015 16:24:05 GMT
Content-Length: 8205
Connection: Keep-Alive
Set-Cookie: request_method=POST; path=/
Set-Cookie: _stuckplaces_session=WmNOeUxyMW9Mc1M3aUx0R3J5U29ZUU85bzJoeEF5T0dCb0F3eG9GdVdsV2hMUGtRSFhIVnRZWHI3bXNKbnlZUTF2c0NJNVQxeEdMYldNSEl5WEVGZlU0dHJWYUNFVWx2bDVaRXJCdWcvd29ZWlRwMHJ6SnhjeHRHeDRmNFByVjI0a1dhbTZZWkxnb0t6Ky9LYnZtTFVZOFE1Tk8vQ1B4T0ZkUG00UGpyU0dpK2NZcUVhLzY1MzhMMnhGZTZ2UkFaOC9VTzNKZXFGQ3B1dWFpcmV3M2JZU1FUdUNnWjhqOUhvbld0M3B2eHdrSVRNT1BNV1ZpSjdQQTVoYkFNMjJYdC0tZktIaFBDc1VZVVltM29mVDU2eDlLUT09--cbf739d14b947b3631d82f2c6d1283a95bede14b; path=/; HttpOnly
and what I expected for response value is something like this
HTTP/1.1 200 OK
{"response":{"user_id":2,"token":"6c54adfb9fd41e33738f3b3707e9726b"}}
view raw
I hope something could help me with this problem, thank you in advance.
You need to modify your sessions controller to respond with JSON containing the required response. You can use this link for reference.

Resources