Rails file upload issue due to Phusion Passenger tmp folder rotation - ruby-on-rails

I have a problem with a rails app running on a newly set up server. The rails app runs on ubuntu/ngnix/passenger.
OS: Ubuntu 12.04.2 LTS
Webserver: ngninx 1.5.4
Passenger v 4.0.24
When uploading larger files through the rails app, when the upload finishes, the app throws a "502 Bad Gateway" error. This only happens for bigger files.
The error log from nginx looks like this:
2014/10/07 14:03:21 [crit] 24511#0: *339 connect() to /home/.../tmp_passenger/passenger.1.0.14062/generation-15/request failed (2: No such file or directory) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: www.xxx.com, request: "POST /path HTTP/1.1", upstream: "passenger:/home/.../tmp_passenger/passenger.1.0.14062/generation-15/request:", host: "www.example.com", referrer: "http://www.example.com/path"
Now, when looking into the folder in /home/.../tmp_passenger/passenger.1.0.14062/generation-15 the generation-N folder seems to be rotating exactly every 60 seconds from .../generation-11 to .../generation-12 and so forth.
Now, obviously any upload - for which passenger uses this generation-N directory as tmp – will fail if it takes longer than a minute, or hits this rotation by chance on shorter uploads.
Now, I really don't know where this rotating of the generation-N folders is happening/configured. I'm pretty sure this is what I need to fix this annoying issue.
From Googling I have the impression that either:
systemd-tmpfiles-clean.service is responsible for the rotation. (but how to change the timing of 60 secs in that case?)
or the respawning of passenger somehow invokes a rotation of the generation-N folder although the PID stays the same so I don't think it's a complete restart of passenger responsible here.

Related

Rails app migrating to AWS Elastic Beanstalk :: Bad Gateway (502)

So I'm migrating from Heroku to AWS Elastic Beanstalk and testing out the waters. I'm following this documentation:
AWS Docs :: Deploy Rails app to AWS
However after following the documentation I keep receiving a Bad Gateway 502 (error).
Here's the specs of my app:
Rails 4.1.8
Ruby 2.1.7
Server Puma
So I checked my /log/nginx/error.log and here is what I see:
2015/11/24 06:44:12 [crit] 2689#0: *4719 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.13.129, server: _, request: "G ET / HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/", host: "my-app-env-mympay5afd.elasticbeanstalk.com"
From this AWS Forum thread it appears as though Puma is not starting correctly.
So the three log files that I have taken a look at are:
/var/log/eb-activity.log
/var/log/eb-commandprocessor.log
/var/log/eb-version-deployment.log
and none of them seem to indicate any errors except for the "secret_key_base" error which I fixed (I used the eb setenv SECRET_KEY_BASE=[some_special_key] command).
One thing that could hint at the source of the issue is /var/log/nginx/rotated/error.log1448330461.gz has the following content
2015/11/24 01:06:55 [warn] 2680#0: duplicate MIME type "text/html" in /etc/nginx/nginx.conf:39
2015/11/24 01:06:55 [warn] 2680#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
But they seem to be warnings rather than severe show stoppers.
Are there any other files that I should be taking a look at?
As another point of reference, I've looked at this SO Post which would seem to imply that I need to enable SSL in order for all of this to work.
Thanks in advance!
Got it.
In my 'production.rb' I had a force_ssl setting and I didn't set up SSL yet since I was just starting out.

Upload a file on server [internal error 500]

On ruby on rails I have written a code where I can upload a file on the amazon console, when i run the code from the localhost i am able to upload the file successfully . But i try to upload it from the swagger i am getting a error called : internal error 500. I have checked the log file and found the following error:
/2013/12/23 09:34:05 [crit] 1705#0: *315335 open() "/tmp/passenger-standalone.1627/client_body_temp/0000000007" failed (2: No such file or directory), client: 10.29.36.248, server: _, request: "POST /v1/models/GTAG2/modelfirmware.json?api_key=5rx2mR3muK1mCydYerw3 HTTP/1.1", host: "dev-api-3.elasticbeanstalk.com"
Can anyone tell me how to fix this bug? In my S3 the folder and bucket is available.
Sounds like you may be encountering issues similar to one of the following:
Phusion-Passenger Issue #654 where something (a daemon) is deleting (cleaning) /tmp files while they are still in use.
Issue Uploading Files from Rails app hosted on Elastic Beanstalk
I'd check to make sure nothing is running on your system that could be deleting/cleaning files under /tmp while Passenger is running.

rails 500 error no production log entry

I have installed a new rails application on the same server as another application. The original is running fine but the new application gives me the infamous "We're sorry but something went wrong" but there is no entry in production log. The last entries in production log are from my migration using rake.
I have found if I run cap deploy:cold it will work but then on the next yupdate will fail again with no sock file. Then cap deploy:cold seems to be required on each update.
edit: If I run /etc/init.d/unicorn_taxidata restart I get "couldn't reload" then if I run it again immediately it starts fine.
The app works in development. Environment is NGINX, unicorn, postgresql, rails 4.0.0.0, ruby 2.0.0p195.
I have this error in my nginx error log:
[crit] 889#0: *65 connect() to unix:/tmp/unicorn.myapp.sock failed (2: No such file or directory) while connecting to upstream, client: 1.123.13.26, server: myapp.com.au, request: "GET /login HTTP/1.1", upstream: "http://unix:/tmp/unicorn.myapp.sock:/login"

403 Error after upgrading passenger (for nginx) is keeping me up at night...where did I go wrong?

I think I've read every question and answer on SO related to passenger/nginx and 403 errors, but none have lead me to a solution, so here I go...
I had Nginx (1.0.6) with Passenger (3.0.9) running beautifully for a rails app for many, many months with no real issues. Tonight I decided to upgrade from Passenger v3.0.9 to v3.0.12 to take advantage of a new feature. After running the install according to the provided instructions (using RVM), I went to the URL served by my rails app and got the dreaded 403 error. The nginx log file first had me thinking it was a permissions error:
directory index of "/home/SimfoUsers/public/" is forbidden, client: , server: , request: "GET / HTTP/1.1", host: ""
But after checking every possible permission, I no longer think that is the issue. I think the problem is actually that passenger is somehow not actually running, and the page is being served as a "normal" webpage by nginx. This is supported by the fact that if I add an index.html file to my rails public directory (/home/SimfoUsers/public/), nginx serves up this file as one would expect. Also, if I run passenger-memory-stats, ZERO passenger processes are running. Shouldn't nginx automatically spawn passenger processes whenever needed, or am I completely missing something here?
Here are the relevant parts of my nginx.conf file:
http {
passenger_root /usr/local/rvm/gems/ruby-1.9.2-p290#Simfo/gems/passenger-3.0.12;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p290#Simfo/ruby;
...
server {
listen 80;
server_name simfo.info www.simfo.info;
root /home/SimfoUsers/public;
passenger_enabled on;
}
}
Basically the only thing that I changed from my previously working config file is to update the passenger_root and passenger_ruby directives to reflect the new version of passenger (3.0.12). So if this is a config file issue, I'm really at a loss to understand it...
I'm not sure whether to just delete this question, or leave it in case it can save someone else the same frustration. This definitely is a face palm moment...
In desperation, I finally rebooted the server. After that, everything worked fine. It seems that at some point the passenger-related processes died and were not re-spawned automatically. One would think that after a fresh installation and reboot of nginx, passenger would be restarted, but apparentally this is not the case. My only advice to anyone having a similar problem is to issue a ps aux | grep passenger (or tasklist on Windows?). You should see one or two processes related to passenger. If not, then something strange is going on, and a reboot might help you as well.

Rails/Nginx: 403

I'm getting a 403 error on my new rails testing page: removed.com:8080. I installed RVM as root, and everything seems to be running correctly (with my limited knowledge of Ubuntu...).
Here's what my log is reading:
2012/03/26 21:53:33 [error] 11698#0: *2 directory index of "/" is forbidden, client: 150.182.203.216, server: rails.pixelcraftwebdesign.com, request: "GET / HTTP/1.1", host: "pixelcraftwebdesign.com:8080"
What am I doing wrong?! :( I've googled this for about 4 hours...
You're attempting to list directory and it appears that .htaccess/server is restricting this. Go to the actual controller/action as per your routes.rb implementation (e.g. pixelcraftwebdesign.com:8080/home/index if you have home_controller and it has index method inside)
Most likely you don't have the correct permissions set on your home or web directory.
Make sure that you have 755 permissions set throughout your path, to allow the non-privileged user that nginx is running as to traverse your directories and read your files.
Some Linux distros will automatically set restricted permissions on your home directory :
/home/user
As a security precaution to prevent other users from reading your files.

Resources