I have Rails (version 4.0.3) application which uses nginx as front-end server to dispatch the requests to actual Unicorn. Whilst developing the app I would like to use Docker on Windows (boot2docker) to run the application and ruby-debug-ide to debug the application remotely.
The original setup works fine (application answers on the host machine) until I replace rails server with
rdebug-ide --port 1234 --host 0.0.0.0 --dispatcher-port 26162 -- bin/rails server
After running this on the Docker container I connect to the remote debugger successfully as it tells on Docker containers bash that breakpoints were added based on what I've set on RubyMine and tells that Unicorn server is now running. I added gem unicorn-rails to make rails server work for Unicorn too.
Now the actual problem is that the nginx can't seem to find the Unicorn when it as ran within the debugger. It just keeps on loading on browser (and with curl) until 504 (gateway timeout) is returned.
The interesting Unicorn configuration contains
app_dir = "/app"
working_directory app_dir
pid "#{app_dir}/tmp/unicorn.pid"
worker_processes 1
listen "/tmp/unicorn.sock", :backlog => 64
I have set up everything as described on JetBrains help pages. On Docker I have all the necessary ports (1234 for debugger, 26162 for dispatcher, 443 for HTTPS) open.
I've crawled Internet and Stack Overflow for hours without any luck and can't find anything to try anymore. Any ideas?
Related
I'm trying to setup apache to use ruby on rails web socket with passenger. I know that Action Cable is not supported on Passenger + Apache, so I'm tryng to use the reverse proxy solution:
https://www.phusionpassenger.com/library/deploy/standalone/reverse_proxy.html
The main application should continue to use the Passenger Apache module while the websocket should use passenger standalone.
I enabled the reverse proxy and changed the vhost config.
<VirtualHost *:80>
...
PassengerRuby /home/rails/.rvm/gems/ruby-2.5.1/wrappers/ruby
<Location "/cable">
ProxyPass "ws://127.0.0.1:4000/cable"
ProxyPassReverse http://127.0.0.1:4000/
ProxyPreserveHost on
</Location>
...
</VirtualHost>
When I start the passenger from the command line
bundle exec passenger start --daemonize --address 127.0.0.1 --port 4000
it works fine, but when I create a service using systemd in Ubuntu 18.04.5 LTS
...
[Service]
Type=forking
WorkingDirectory=/mnt/xfeature/srv/www/f3.xxxx.xxx/current
Environment=RAILS_ENV=feature
User=rails
Group=www-data
UMask=0002
ExecStart=/home/rails/.rvm/bin/rvm-shell -c 'bundle exec passenger start --daemonize -e feature --address 127.0.0.1 --port 4000 --log-level 5'
ExecStop=/home/rails/.rvm/bin/rvm-shell -c 'bundle exec passenger stop --port 4000'
....
it fails usually with this error.
[ E 2021-05-13 09:52:13.3607 21447/Tz age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /mnt/xfeature/srv/www/f3.xxx.xxx/releases/20210513094622: An operating system error occurred while preparing to start a preloader process: Cannot change the directory '/tmp/passenger.spawn.XXXXgMx55z/envdump' its UID to 1001 and GID to 1001: Operation not permitted (errno=1)
Error ID: 847da63a
Error details saved to: /tmp/passenger-error-5S5Syq.html
and the websocket connection cannot be established. I checked the /tmp permission and are OK.
Any suggestion?
We had some strange issues with Apache and Passenger recently. It turns out Apache automatically updated and changed the PrivateTmp setting to true, which caused a similar error message.
I'm not sure if that is what is causing your error, but you could check that to verify that PrivateTmp is set to false.
Our configuration is:
/etc/systemd/system/apache2.service.d/override.conf
override.conf Contents:
PrivateTmp=false
I'm not certain how that override.conf file is loaded. I assume there is a configuration somewhere looking for an override file and it is using it.
I am triyn to deploy two different rails app in one Ec2 i can run one each time and work ok, but i need the 2 app running at same time and that can be accessed from anywhere not only localhost,I enable (add rule) two tcp port 3000 and 3001, this is my try:
/path/app1$ rails s -d
/path/app2$ rails s -b0.0.0.0 -p 3001 -d
this is the ps -ef command output
dev+ 3028 1 0 17:10 ? 00:00:00 puma 3.11.2 (tcp://localhost:3000) [/]
dev+ 3160 1 0 17:14 ? 00:00:00 puma 3.11.3 (tcp://0.0.0.0:3001) [/]
also try to run app1 with -b0.0.0.0 so it can listen from anywhere, but same result: only 1 app is listening on 0.0.0.0.
What I am missing? How can I run two servers at same time and listen both on 0.0.0.0.
thanks
By default, according to the Rails documentation, the server will only listen on the localhost / loopback interface. This is actually confirmed in the output snippet that you posted.
In the first command for app1, you aren't telling it to listen on 0.0.0.0, so you'd need to change your first command to:
/path/app1$ rails s -b0.0.0.0 -p 3000 -d
Both applications can listen on 0.0.0.0, but they can't share the same port. You have already configured app1 to listen on port 3000 (Rails default), and app2 to listen on port 3001, so they should both coexist peacefully, once you make the change above.
See also: What does binding a Rails Server to 0.0.0.0 buy you?
I am deploying a rails add using Capistrano on remote Ubuntu 14.04 server.
Finally when I restart nginx, web page shows an error
We're sorry, but something went wrong.
I hope to know what cause the error, what command can I use to see log from remote server
try
bundle exec tail -f log/production.log
if no error is seen there then first check your nginx logs at
tail -f /var/log/nginx/access.log
or
tail -f /var/log/nginx/error.log
if you see some request logging there then that means request is coming to server and its not passing to puma server.
There can be two reasons about why request is not being passed to puma, either your address of puma process is not correct in nginx file or puma server is not running or there was some error and puma was shutdown when request reached it.
to see puma process use this command
ps aux | grep puma
it should print one line out of many lines
app 22528 0.1 0.5 296532 23912 ? Ssl 16:42 0:00 puma 2.11.1 (tcp://0.0.0.0:8080) [20180110213633]
now using this information I can map address like this in nginx
upstream app {
# Path to Puma SOCK file, as defined previously
server 0.0.0.0:8080;
}
here I bind the puma local ip with port to nginx process.
Make sure your puma.rb binds properly to puma.sock file as for one of my project I am doing like this in config/puma.rb
bind "unix:///Users/Apple/RAILS_PROJECTS/tracker/tmp/sockets/puma.sock"
I just changed from thin to puma at the recommendation of Heroku. When I start my rails app using the puma server it responds:
=> Booting Puma
=> Rails 4.2.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.3 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000
However if I go to http://0.0.0.0:3000 in the browser, which was my old localhost with the thin server, it does not respond. However, if I open http://localhost:3000, then it works. It appears that the definition of localhost has changed.
So, what is localhost? In particular, what sort of object is it, how is it defined, how do I see the actual ip address, and why does puma change it?
If you're trying to get Rails to bind to a different ip, the way to do that is with the -b option. To bind it to 0.0.0.0 instead of the Rails-default localhost you'd want to run something along the lines of rails s -b 0.0.0.0
Note: To be explicit, it may not be a bad idea to throw the -p 3000 option in there too (sets the port), even though that default is not likely to change. More info on the available options can be found by running rails s -h as well.
Localhost is the IPv4 loopback IP address 127.0.0.1. It is used instead of the hostname of a computer. Localhost can sometimes mean this computer.
For example, directing a web browser installed on a system running an HTTP server to http://localhost will display the home page of the local website.
Here's an interesting Wikipedia article
https://en.wikipedia.org/wiki/Localhost
Using nginx and phusion passenger to host site http://example.com and is running fine.However, I want to be able to forward http://example.com:3000 to the webrick server raise by running command rails s. How do i do that ?