I'm using Rails 3.2 with passenger+nginx. I want to display nice custom 500 page when the db server is down. I want to show something when my rails app cannot be started. Here is my nginx:
server {
listen 80;
server_name localhost;
root /var/www/store/public;
error_page 500 /500.html;
# root
location / {
passenger_enabled on;
rails_env production;
passenger_use_global_queue on;
}
}
The above configuration doesn't work at all. When it happens, it shows only:
Internal Server Error (500)
Any idea?
Phusion Passenger author here. Use passenger_intercept_errors off.
from the passenger documentation http://www.modrails.com/documentation/Users%20guide%20Nginx.html#PassengerFriendlyErrorPages
passenger_friendly_error_pages off
Which can be placed inside the http block, server block or location block, will not show the passenger error for startup failures and I believe link to the nginx supplied 500 error page.
mariow's link led me to the answer. The error files are in the templates folder. I use rvm, so my templates folder is at /home/forest.handford/.rvm/gems/ruby-2.0.0-p481/gems/passenger-4.0.50/resources/templates/ . Use find / -name templates | grep passenger to find yours. I'm changing undisclosed_error.html.template for my site, as it is the error that occurs when people type an invalid URL .
Related
I am having a problem with getting a Vue app to load via Nginx. Basically, the npm run build finishes without any errors but when I go to the root URL the page is blank.
I get the following error, related to chunk-vendors and app, in dev tools console:
Uncaught SyntaxError: Unexpected token '<'
When I click on the related files it shows the html on a single line with a red squiggle line underneath and when I scroll over there is nothing inside the <div id="app">.
The build folder path is /home/ubuntu/apps/client/vue-crm/dist and my Nginx configuration looks like this:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/ubuntu/apps/client/vue-crm/dist;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
root /home/ubuntu/apps/client/vue-crm/dist;
try_files $uri/ /index.html =404;
}
}
I have run sudo nginx -t which comes back OK. Disclaimer, I am a bit of a newb when it comes to deploying using Vue CLI build and Nginx configuration so I could be missing something obvious.
I am running out of ideas on where the problem is. It seems my app is building fine, I just can't get it to load. Any help is much appreciated.
I have NGINX running as a proxy service and want to set SSL key depending on the $ENV variable (in Docker Compose file).
I added to the nginx.conf:
env ENVKEY;
And then in the config file:
server {
resolver 10.0.0.4 valid=300s;
resolver_timeout 60s;
server_name _;
listen 443;
ssl on;
# perl_set $envkey 'sub { return $ENV{"ENVKEY"}; }';
set_by_lua $envkey 'return os.getenv("ENVKEY")';
ssl_certificate /etc/nginx/ssl/jm-website-$envkey.crt;
ssl_certificate_key /etc/nginx/ssl/jm-website-$envkey.key;
I also tried to use perl_set - but it can be used in the location only, but ssl_certificate - in the http or server blocks.
Using set_by_lua - I have an error:
nginx: [emerg] BIO_new_file("/etc/nginx/ssl/jm-website-$envkey.crt")
failed (SSL: error:02001002:system library:fopen:No such file or
directory:fopen('/etc/nginx/ssl/jm-website-$envkey.crt','r')
error:2006D080:BIO routines:BIO_new_file:no such file)
Although variable present in the environment:
root#d0718b0a3361:/etc/nginx# echo $ENVKEY
dev
What I'm doing wrong here?
Maybe there is better approach?
I do know that this is an old thread. I'm posting this for posterity's sake.
I was having the same problem as you were/are.
What is happening is that there's an order to when the lua blocks gets executed. set_by_lua happens right after the certificate is validated.
What you could do is either render you nginx.conf using a render engine of your choice (e.g.: python jinja) or you could write your own ssl_certificate_by_lua_block that reads from an environment variable. Here is an exemple of an implementation using said block. You could also check how Kong does it.
Hope it helps :)
I would like to run two versions of my rails site, one for production and one for development. The production one will listen on port 80 and the development will listen on port 9033. Here are my config server blocks which are located in the same file
server {
listen 80 default_server;
server_name mywebsite.com;
passenger_enabled on;
passenger_app_env production;
root /path/to/public/dir;
}
server {
listen 9033 default_server;
server_name mywebsite.com;
passenger_enabled on;
passenger_app_env development;
root path/to/public/dir;
passenger_friendly_error_pages on;
}
The problem lies in that when I try to connect to the website through my browser, regardless of which port I use I always get the version of the website corresponding to the environment specified in the first server block. So in the example I gave above, it'd always serve the production version of my website.
Why is it that the first server block overrides the second, and how can I make it so that I can access either version of my website without going in a manually changing the config files and reloading nginx?
UPDATE:
None of the suggestions were working, even after clearing the browser cache before sending every HTTP request. I changed my server blocks to the following in the hopes of my server returning different version of the website
server {
listen *:80;
server_name mywebsite.com;
passenger_enabled on;
passenger_app_env production;
root /home/alex/code/m2m/public/;
}
server {
listen *:80;
server_name dev.mywebsite.com;
passenger_enabled on;
passenger_app_env development;
root /home/alex/code/m2m/public/;
passenger_friendly_error_pages on;
}
and then added the following line in my /etc/hosts file
my.ip.addr.ess dev.mywebsite.com
But requests to both domains result in only the production version of my website being returned. Note I'm using the default nginx.conf file. Is there a way I can debug my browser (Chrome v40.0.2214.111 (64-bit)) to see if/where my requests are being altered? I'm thinking the problem lies clientside since the advice the commenters have given me seems like it should work.
And if you try this :
listen *:80;
and
listen *:9033;
This was my recommendation regarding the question that aims nginx config.
By putting those listen directives, according to nginx doc, nginx will first match ip:port server blocks and then look at server_name directives in server blocks that matched IP:port. So if request containing right 'port' end in the wrong environment this has something to do with either the app or the passenger directives.
I'm on a VPS. I created a new rails app with rails new rails_app -d mysql.
I'm running nginx with passenger. I'm running Rails 3.2.12 and Ruby 1.9.3. In my nginx.conf file I added the following to the server directive:
listen 80;
server_name www.mydomain.com;
passenger_enabled on;
root /home/mike/www/rails_app/public;
rails_env production;
When I point to www.mydomain.com I see Welcome aboard You’re riding Ruby on Rails!. When I click on About your application’s environment I get this error:
The page you were looking for doesn't exist.
When I check my production.log I see this error and don't know what to do with it:
ActionController::RoutingError (No route matches [GET] "/rails/info/properties")
I've been up all night and have read all SO issues similar to this but still I cannot resolve my issue. If I run this in development everything works fine.
EDIT
I found this explanation for a Rails 2.3.4 problem: The link fires off an AJAX request to rails/info/properties. The properties action is defined in the Rails::InfoController which lives in /rails/railties/builtin/rails_info/rails/info_controller.rb.
The route doesn't need to be explicitly defined because it conforms to the Rails default route of :controller/:action/:id (although there is no ID in this case and the controller lives within a Rails namespace.)
But I don't see info_controller.rb anywhere.
Ok I found this: config.consider_all_requests_local is a flag. If true then any error will cause detailed debugging information to be dumped in the HTTP response, and the Rails::Info controller will show the application runtime context in /rails/info/properties. True by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement local_request? in controllers to specify which requests should provide debugging information on errors.
but setting this to false does nothing.
EDIT 2
Ok, I'm an idiot. Found this somewhere: You're clicking the "About your application’s environment" link on the Rails default index.html page. This link only works in development environment, not in production.
And this entire night I thought my Rails app wasn't working. So I guess I'll give up and go to sleep.
You forgot to add passenger_base_uri:
server {
listen 80;
server_name domain.com;
charset utf-8;
root /www/domain.com/public_html;
passenger_enabled on;
passenger_base_uri /blog;
rails_spawn_method smart;
rails_env production;
}
Also check that passenger and rails work in the same environment (production or development).
For those who might encounter this problem in the future, first check your production logs in your server.
ssh into your server, ssh username#serverIP
Check the last 20 or so error messages tail -20 /home/username/appname/current/log/production.log
If it's a bug in your code (mine was returning an empty array due to an empty db), then fix that bug and run cap production deploy once again.
Repeat to check for more errors.
Same problem is also faced by me, but I found later wards due to permission, our application is not able to access the specific folder.
Try this command :
chmod -R 777 {name of your project folder}/
Folks
I Am trying to set up ruby on rails 3.2.3 with passenger 3.0.12 and nginx 1.2. I have followed instructions to compile nginx with passenger module. Following is my nginx configuration. When I try to go to the root page (using curl localhost), it gives me 403 forbidden error. It does not seem to pass the request on to passenger. Let me know if I am missing something simple. Thank you,
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /home/ubuntu/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12;
passenger_ruby /home/ubuntu/.rvm/wrappers/ruby-1.9.3-p194/ruby;
rails_env development;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
passenger_enabled on;
location / {
root /home/ubuntu/rails/myapp/public;
}
}
}
EDIT
If I do the following:
1) create a new app - dummy
2) Change the config.ru to print 'hello world'
3) change the root to point to dummy app's public directory
Then the error goes away.
Also, if I create a brand new rails app, I am able to access the default rails app page. I have also tried to make directory perms 777 for the entire myapp directory structure. No joy.
Solved it.The passenger_enabled clause has to be moved to within the location block.