I have a rail app that serves multiple domain_name and is deployed by nginx & passenger. I need to put one domain under maintenance mode while the other still work as usual. Here is my config:
server {
listen 80;
server_name domain1.com domain2.com domain3.com domain4.com;
error_page 503 http://$host/maintenance.html;
location /maintenance.html {
# Allow requests
}
location / {
root /var/www/myapp/public; # <--- be sure to point to 'public'!
error_page 503 http://$host/maintenance.html;
passenger_enabled on;
rails_env development;
passenger_use_global_queue on;
if (-f /var/www/myapp/public/maintenance.html) {
return 503;
}
}
}
The above config would cause all domains under maintenance. However, I want to put domain1.com is under maintenance mode. How would I achieve this?
you can add another server entry for server "domain1.com" which serve request for this domain only. like:
server {
listen 80;
server_name domain1.com
error_page 503 http://$host/maintenance.html;
root /your/root/directory/
if (-f $document_root/maintenance.html){
rewrite ^(.*)$ /maintenance.html last;
break;
}
location /maintenance.html {
# Allow requests
}}
you need to ensure following
The "domain1.com" should be removed from previous server
entry
maintenance.html page should be
present in /your/root/directory/
Related
I'm trying to make images load on Spree 3.1.0 + Passenger 5.0.30 + Nginx + Capistrano 3.5 + Digital Ocean, I have followed Go Rails Tutorial and Spree documentation but no luck at the moment.
Weird... Is loading my css files but not loading my image-background
my /etc/nginx/sites-available/default file:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name rodeobest.com;
passenger_enabled on;
rails_env production;
root /home/deployer/RMG_rodeobest/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# if the request is for a static resource, nginx should serve it dir$
# and add a far future expires header to it, making the browser
# cache the resource and navigate faster over the website
location ~ ^/(spree|system|assets)/ {
root /home/deployer/RMG_rodeobest/current/public;
expires max;
break;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico)$ {
root /home/deployer/RMG_rodeobest/current/public;
}
}
As documentation says, I've changed location ~ ^/(system|assets)/ to location ~ ^/(spree|system|assets)/ and restart the server, but as I said, no luck. Any idea? thanks in advance
References:
Reference 1
Reference 2
I have a web application ruby on rails who is not configured to multithreading.
In nginx config, I set up an upstream block to be load balanced.
Like this :
upstream myapp {
server 127.0.0.1:3075;
server 127.0.0.1:3076;
server 127.0.0.1:3077;
}
I set up also 3 process thin with 3 ports (3075,3076,3077).
I think when my first application '127.0.0.1:3075' is busy, all the request will be balanced automatically to my second application '127.0.0.1:3076' or the third one.
But load balancing is not work, even though my three web applications are running correctly independent.
Please help me to find errors.
------------------- nginx config --------------------
upstream myapp_hosts {
server 127.0.0.1:3075;
server 127.0.0.1:3076;
server 127.0.0.1:3077;
}
server {
listen 80;
server_name myapp.mydomain.com;
rewrite ^(.*)$ https://myapp.mydomain.com$1 permanent; # rewrite for https, i have another bloc server listen 443.
access_log /var/log/nginx/myapp.access.log;
location / {
proxy_pass http://myapp_hosts/;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 16k;
proxy_buffers 32 16k;
proxy_busy_buffers_size 64k;
}
location /public {
root /var/www/nemo/;
}
location /images {
root /var/www/nemo/assets/;
}
location /javascripts {
root /var/www/nemo/assets/;
}
location /stylesheets {
root /var/www/nemo/assets/;
}
client_max_body_size 10m;
client_body_buffer_size 128k;
client_header_buffer_size 64k;
}
What is the purpose of your rewrite?
rewrite ^(.*)$ http://myapp.mydomain.com$1 permanent;
It looks like it's going to constantly redirect anything to itself based off of those rules, resulting in a redirect loop. You may have mixed this line up with an HTTPS redirect configuration you found somewhere else, perhaps?
Try removing that line and see if it works.
I have a Rails app running on nginx 1.2.0 and passenger 3.0.7. I would like to have the custom error pages in the rails app (e.g. /rail_app/public/500.html) be displayed when the appropriate http error occurs within the app.
Here is my current nginx config file:
http {
passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7;
passenger_ruby /usr/bin/ruby;
include mime.types;
default_type application/octet-stream;
#access_log /opt/nginx/logs/access.log main;
sendfile on;
#tcp_nopush on;
server {
listen 80;
server_name localhost;
root /var/www/dashboard/current/public;
passenger_enabled on;
passenger_min_instances 1;
# listen 443;
# ssl on;
# ssl_certificate /opt/nginx/conf/server.crt;
# ssl_certificate_key /opt/nginx/conf/server.key;
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www/dashboard/current/public/;
}
}
}
This configuration does not show the rails app customer error page rather just sends the http error status code to the client.
Anyone know what it takes to have nginx/passenger send the rails app custom error page to the client with the http error status code?
Please try the following:
# We use the x just because it is for all 5xx errors.
error_page 500 502 503 504 /5xx.html;
location = /5xx.html {
alias /var/www/dashboard/current/public/;
}
Reconfiguring the root directive makes no sense, as it is already set to the path you specified before. The alias ensures that the specific location is internally matched to a different location on the file system. All incoming request parameters should be passed along and if your Rails app is taking care of things at this point it should answer. Just make sure that your Rails app isn't answering with a 500 status again (I don’t know what would happen then).
Related Links
alias
You're probably missing passenger_intercept_errors on; in your nginx config
see the passenger docs for this directive for more info
The config I use:
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
I've got a Rails app deployed via nginx/passenger. It will have multiple domains pointing to it.
I'm wondering if it's possible to configure nginx so that any URL that matches [somedomain.com]/blog/ will be servered by PHP/WordPress located in a different directory.
So, for example:
domain1.com, domain2.com, & domain2.com/some-resource/1 point to the Rails app at /var/rails/mainapp/
but domain1.com/blog/ goes to /var/sites/domain1.com/
and domain2.com/blog/ goes to /var/sites/domain2.com/
server {
location /blog {
alias /var/sites/domain1.com/;
}
location / {
}
}
You need define you /blog before / location
Here is my config. Hope it helps someone.
# Redirect all requests containing 'www.your-website.ru'
# to 'your-website.ru'
server {
listen 80;
server_name www.your-website.ru;
rewrite ^(.*) http://your-website.ru$1 permanent;
}
server {
listen 80;
server_name your-website.ru;
access_log logs/your-website.ru.log;
root /path-to-your-website.ru/current/public;
#####################
# Rails
#####################
location / {
rails_env production; # this is a production server
passenger_enabled on; #
I'm trying to migrate to nginx from Apache using Passenger in both instances to host a Rails app. The app takes a request, which is for an image- if the image exists at /system/logos/$requestedimage then it should get served, or it should be allowed to hit the Rails app to generate it if needed (where it is then cached to /system/logos).
In Apache I used the following:
RewriteCond %{DOCUMENT_ROOT}/system/logos/%{REQUEST_FILENAME} -f
RewriteRule ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1
This worked fine. The assets. subdomain is another subdomain but with the same root, just Passenger disabled, specifically set up for hosting static files (expires-wise).
In nginx I am using the following:
server {
listen 80;
passenger_enabled on;
server_name clg.eve-metrics.com www.clg.eve-metrics.com;
root /opt/www/clg/current/public;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml text/css application/javascript;
gzip_disable msie6;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
if (-f $document_root/system/logos$request_filename) {
rewrite ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1 break;
}
}
This doesn't work so well. At all, in fact. It never redirects to the cached path and it never hits the Rails app. It's like nginx is assuming it's a static asset so not passing it on to Passenger. Is there a way to stop this behaviour so it hits the app?
My rails application is running on nginx and passenger. I have moved my rails cache directory from the default /public to /public/system/cache/. To make it work, I had to insert this into my vhost config file:
if (-f $document_root/system/cache/$uri/index.html) {
rewrite (.*) /system/cache/$1/index.html break;
}
if (-f $document_root/system/cache/$uri.html) {
rewrite (.*) /system/cache/$1.html break;
}
I remember that I too tried to make it work with $request_filename, but didn't get it to work. Try with $uri instead and see if it works :-)
James, please try this configuration file
https://gist.github.com/711913
and pay attention on this location config:
location ~* \.(png|gif|jpg|jpeg|css|js|swf|ico)(\?[0-9]+)?$ {
access_log off;
expires max;
add_header Cache-Control public;
}
passenger won't let Rails to manage your assets files if you have right permissions (user run nginx should has permissions to access to file directly)