Rails 6 Application deployment fails using Elastic Beanstalk - 502 errors - ruby

Trying to deploy my rails application to elastic beanstalk but I'm getting 502 errors. I'm running React on Rails and I've tried to follow this -> Rails application deployed on Elastic Beanstalk with Puma fails - 502 errors on every request but no luck. Any ideas?
Here are the logs
/var/logs/nginx/error.log
2020/01/09 04:11:45 [warn] 3083#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2020/01/09 04:20:04 [crit] 3087#0: *108 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.44.209, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/", host: "staging5.q39956drtr.ap-southeast-1.elasticbeanstalk.com"
2020/01/09 04:25:23 [crit] 3087#0: *185 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.44.209, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/", host: "staging5.q39956drtr.ap-southeast-1.elasticbeanstalk.com"
2020/01/09 04:25:24 [crit] 3087#0: *185 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.44.209, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/favicon.ico", host: "staging5.q39956drtr.ap-southeast-1.elasticbeanstalk.com", referrer: "http://staging5.q39956drtr.ap-southeast-1.elasticbeanstalk.com/"
Puma
healthd 2775 0.0 3.4 683640 34356 ? Ssl 04:11 0:04 puma 2.11.1 (tcp://127.0.0.1:22221) [healthd]
root 7841 1.5 0.2 58788 2612 ? Ss 05:56 0:00 su -s /bin/bash -c bundle exec puma -C /opt/elasticbeanstalk/support/conf/pumaconf.rb webapp
webapp 7940 43.0 1.1 70180 11460 ? Rs 05:56 0:00 /opt/rubies/ruby-2.6.5/bin/ruby /opt/rubies/ruby-2.6.5/bin/bundle exec puma -C /opt/elasticbeanstalk/support/conf/pumaconf.rb
root 7957 0.0 0.2 110516 2136 pts/0 S+ 05:56 0:00 grep --color=auto puma
pumaconf.rb
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
port ENV.fetch("PORT") { 3000 }
#
environment ENV.fetch("RAILS_ENV") { "development" }
# pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
bind "unix:///var/run/puma/my_app.sock"
pidfile "/var/run/puma/my_app.sock"
plugin :tmp_restart

Related

socat localhost proxy with 'Connection refused'

I want to play with socat to setup a localhost proxy , which could redirect my request from local proxy I setup to a remote server.
Below are 2 commands I try (by google)
Command 1: works right on localhost
start socat server
socat -d TCP6-LISTEN:8080,fork,reuseaddr TCP4:drsol.com:80
client connect socat server
curl -I -6 http://localhost:8080/
HTTP/1.1 200 OK
Date: Sun, 25 Dec 2022 13:06:11 GMT
Server: Apache/2.2.15 (CentOS)
Last-Modified: Tue, 10 Jun 2014 17:35:11 GMT
ETag: "2482ce4-2-4fb7ebff1050b"
Accept-Ranges: bytes
Content-Length: 2
Connection: close
Content-Type: text/html; charset=UTF-8
Command 2: 'Connection refused' error on localhost server terminal
setup socat server
socat TCP6-LISTEN:8000 PROXY:localhost:drsol.com:80,proxyport=8080
connect socat server
curl -v http://localhost:8000/
* STATE: INIT => CONNECT handle 0x55fce853a968; line 1789 (connection #-5000)
* Uses proxy env variable no_proxy == 'localhost,127.0.0.0/8,::1'
* Added connection 0. The cache now contains 1 members
* family0 == v4, family1 == v6
* Trying 127.0.0.1:8000...
* STATE: CONNECT => CONNECTING handle 0x55fce853a968; line 1850 (connection #0)
* Connected to localhost (127.0.0.1) port 8000 (#0)
* STATE: CONNECTING => PROTOCONNECT handle 0x55fce853a968; line 1982 (connection #0)
* STATE: PROTOCONNECT => DO handle 0x55fce853a968; line 2003 (connection #0)
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.80.0
> Accept: */*
>
* STATE: DO => DID handle 0x55fce853a968; line 2099 (connection #0)
* STATE: DID => PERFORMING handle 0x55fce853a968; line 2218 (connection #0)
* STATE: PERFORMING => DONE handle 0x55fce853a968; line 2417 (connection #0)
* multi_done
* Empty reply from server
* The cache now contains 0 members
* Closing connection 0
* Expire cleared (transfer 0x55fce853a968)
curl: (52) Empty reply from server
on the socat server terminal "Connection refused"
2022/12/25 21:10:42 socat[46697] E connect(5, AF=2 127.0.0.1:8080, 16): Connection refused
My question is : what was the difference between command 1 and command 2 , and why the connection refused happend on command 2?
(I am new to socat and on my way of learning it)

unable to access Werkzeug server running in vagrant machine from the host machine

I created a vagrant machine. Here is my Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-18.04"
config.vm.network "forwarded_port", guest: 5000, host: 5000
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get update
sudo apt-get -y install python3-pip
sudo pip3 install flask
SHELL
end
everything works fine inside the virtual machine. Running the following app works fine inside the virtual machine.
basic.py:
from flask import Flask, jsonify
app = Flask(__name__)
#app.route('/')
def index():
return jsonify({"message": "Hello World"})
if __name__ == '__main__':
app.run(debug=True, port=5000)
Result of running basic.py inside the virtual machine
But trying to access the server from the host machine (via chrome browser) gives the message below:
unable to access the server from the host machine
trying to reload the browser
I tried to disable my antivirus (Norton just to check if Norton is filtering and blocking ports) but I have the same result. Did anyone else experience the same issue? Can someone help figure out what's wrong then how to fix it?
#Mirko Ebert, Trying to reach the server via "curl -v localhost:5000" gives the response below:
from inside the VM:
vagrant#vagrant:~$ curl -v localhost:5000
* Rebuilt URL to: localhost:5000/
* Trying ::1...
* TCP_NODELAY set
* connect to ::1 port 5000 failed: Connection refused
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.58.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: application/json
< Content-Length: 31
< Server: Werkzeug/0.14.1 Python/3.6.7
< Date: Thu, 13 Dec 2018 21:15:45 GMT
<
{
"message": "Hello World"
}
* Closing connection 0
From the host machine:
$ curl -v localhost:5000
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0*
Trying ::1...
* TCP_NODELAY set
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.62.0
> Accept: */*
>
* Recv failure: Connection was reset
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
* Closing connection 0
curl: (56) Recv failure: Connection was reset

use polipo to convert shadowsocks into an HTTP proxy

My ssserver is started by docker image oddrationale/docker-shadowsocks:
docker run -d -p 1984:1984 oddrationale/docker-shadowsocks -s 0.0.0.0 -p 1984 -k paaassswwword -m aes-256-cfb
Then I use sslocal command to get local proxy.
sslocal -c /etc/shadowsocks.json -d start --pid-file /data/tmp/sslocal.pid --log-file /data/tmp/sslocal.log
/etc/shadowsocks.json is like this:
{
"server":"127.0.0.1",
"server_port":1984,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"paaassswwword",
"timeout":600,
"method":"aes-256-cfb"
}
I use polipo to convert shadowsocks to http proxy, my /etc/polipo/config is:
proxyAddress = 0.0.0.0
socksProxyType = socks5
socksParentProxy = 127.0.0.1:1080
daemonise = true
pidFile = /data/tmp/polipo.pid
logFile = /data/tmp/polipo.log
I edit the iptables rules to make port 8123 can be accessed. I can access http://host:8123 in browser, and the proxy looks work:
http_proxy=http://host:8123 curl -v google.com
the output is like this:
* Rebuilt URL to: google.com/
* Trying host...
* Connected to host (host) port 8123 (#0)
> GET HTTP://google.com/ HTTP/1.1
> Host: google.com
> User-Agent: curl/7.43.0
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 302 Found
< Content-Length: 262
< Date: Thu, 13 Apr 2017 09:52:34 GMT
< Cache-Control: private
< Content-Type: text/html; charset=UTF-8
< Referrer-Policy: no-referrer
< Location: http://www.google.com.sg/?gfe_rd=cr&ei=YkrvWPnOM-XLugTRgZDQBA
< Connection: keep-alive
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
here.
</BODY></HTML>
* Connection #0 to host host left intact
The command does not always run successfully, and sometimes I get the following error:
* Rebuilt URL to: google.com/
* Trying host...
* Connected to host (host) port 8123 (#0)
> GET HTTP://google.com/ HTTP/1.1
> Host: google.com
> User-Agent: curl/7.43.0
> Accept: */*
> Proxy-Connection: Keep-Alive
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
The output of netstat -tlnp is:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:1080 0.0.0.0:* LISTEN 5067/python
tcp 0 0 0.0.0.0:8123 0.0.0.0:* LISTEN 9704/polipo
tcp6 0 0 :::8388 :::* LISTEN 4238/docker-proxy
I really can't find the reason, thank you for your help.
google use https, not http, try
https_proxy=http://host:8123 curl -v https://www.google.com

Puma log config -- 200 OK going to STDERR

My pumaconf.rb has this line:
stdout_redirect '/var/log/puma/puma.log', '/var/log/puma/puma-err.log', true
puma.log contains:
=== puma startup: 2016-09-07 23:33:01 +0000 === [4433] - Worker 0 (pid: 4436) booted, phase: 0
puma-err.log contains:
10.10.10.1 - - [08/Sep/2016:00:03:27 +0000] "GET /health HTTP/1.0" 200 - 0.0005
10.10.10.1 - - [08/Sep/2016:00:03:27 +0000] "GET /health HTTP/1.0" 200 - 0.0005
Any tips on what I may have incorrectly setup?
Edit:
A little more info on my side -- I set up a new test in a clone of the puma code, with the following config:
log_requests
stdout_redirect "t4-stdout", "t4-stderr", true
pidfile "t4-pid"
bind "tcp://0.0.0.0:10103"
rackup File.expand_path('../hello.ru', File.dirname(__FILE__))
daemonize false
And wrote a test around "200 OK should only be in stdout, not in stderr" and everything is passing.
I'm pretty stumped why spinning up a puma server from the base repo is acting so differently, but I will keep digging.

webpage download using cURL utility - proxy cycle issue

I am trying to access google.com from my work using cURL for windows 32-bit(with SSH version). I am connecting via my company's proxy server but I am getting 400 proxy cycle detected error. Could someone please let me know why I am getting this error. The command & error message are as follows(Proxy IP changed to XXXX):
Command:
%curl -A "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0b7pre) Gecko/20100925 Firefox/4.0b7pre" -v --proxy-ntlm XXX.XXX.XXX.XXX:8080 -U name:password -I http://www.google.com
Output:
Enter proxy password for user 'name':
* Rebuilt URL to: XXX.XXX.XXX.XXX:8080/
* About to connect() to XXX.XXX.XXX.XXX port 8080 (#0)
* Trying XXX.XXX.XXX.XXX...
* Adding handle: conn: 0xcb0520
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0xcb0520) send_pipe: 1, recv_pipe: 0
* Connected to XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX) port 8080 (#0)
> HEAD / HTTP/1.1
> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0b7pre) Gecko/20100925 Firefox/4.0b7pre
> Host: XXX.XXX.XXX.XXX:8080
> Accept: */*
>
< HTTP/1.1 400 Cycle Detected
HTTP/1.1 400 Cycle Detected
< Date: Mon, 25 Nov 2013 11:56:06 GMT
Date: Mon, 25 Nov 2013 11:56:06 GMT
< Via: 1.1 localhost.localdomain
Via: 1.1 localhost.localdomain
< Cache-Control: no-store
Cache-Control: no-store
< Content-Type: text/html
Content-Type: text/html
< Content-Language: en
Content-Language: en
< Content-Length: 288
Content-Length: 288
<
* Connection #0 to host XXX.XXX.XXX.XXX left intact
* Rebuilt URL to: http://www.google.com/
* Adding handle: conn: 0xcb12f8
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 1 (0xcb12f8) send_pipe: 1, recv_pipe: 0
* About to connect() to www.google.com port 80 (#1)
* Trying 173.194.115.50...
* Connection refused
* Trying 173.194.115.51...
* Connection refused
* Trying 173.194.115.49...
* Connection refused
* Trying 173.194.115.48...
* Connection refused
* Trying 173.194.115.52...
* Connection refused
* Failed connect to www.google.com:80; Connection refused
* Closing connection 1
curl: (7) Failed connect to www.google.com:80; Connection refused
For what it's worth, I am able to connect to google.com via browser using the said proxy address. And I am sure that I am giving the password(for the proxy) correctly.
You have set the proxy via --proxy parameter or -x parameter not via --proxy-ntlm, try this, please
curl -A "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0b7pre) Gecko/20100925 Firefox/4.0b7pre" -L --proxy http://xxx.xxx.xxx.xxx:8080 --proxy-ntlm -U name:password http://www.google.com
If you enter in a new redirect cycle you can try without -L parameter or set the --max-redirs parameter.
cURL manpage
I believe you are being knocked back due to authentication. Your work proxy likely requires authentication before it will allow you to access websites through it.
If your work uses Active Directory SSO (Single Sign On), try the following with your domain username and password:
curl --ntlm --user username:password http://www.google.com
Or not, try the following for basic auth:
curl --user username:password http://www.google.com

Resources