Spree not loading images on Nginx - ruby-on-rails

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

Related

Assets not loading in newly deployed Rails app

Just deployed my rails app for the first time and none of my assets are loading. I don;t use the Asset pipeline but have left it switched on for any gems that may use it. I have a Gulp workflow configured which outputs all assets to the public/assets directory.
My my layout I call:
<link rel="stylesheet" href="<%= gulp_asset_path('stylesheets/application.css') %>">
which gives me:
<link rel="stylesheet" href="/assets/stylesheets/application.css">
Any ideas?
Edit:
My conf file:
server {
listen 80 default_server;
server_name dev.myapp.co.uk;
passenger_enabled on;
rails_env production;
root /home/deploy/myapp/current/public;
location /assets {
gzip_static on;
expires max;
add_header Cache-Control public;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

rails app on nginx+passenger not showing custom error pages

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;
}

Rails 3 running in subdirectory, assets not found

I'm serving two Rails sites using nginx. Rails1 does not use the asset pipeline but Rails2 does. Rails2 also uses a prefix to differentiate it from Rails1. For example:
http://myhost -> Rails1
http://myhost/abc -> Rails2
Both sites are running, however any reference to assets on the Rails2 site are not found.
Here's what my pseudo nginx.conf looks like:
http {
upstream rails1 {
server 127.0.0.1:3000;
}
upstream rails2 {
server 127.0.0.1:3030;
}
server {
location ~ ^/assets/ {
expires max;
add_header Cache-Control public;
access_log off;
}
location /abc {
proxy_pass http://rails2;
}
location / {
proxy_pass http://rails1;
}
}
}
Also, the routes.rb in my Rails 2 app:
Rails2App::Application.routes.draw do
scope '/abc' do
resources :projects
root :to => 'home#index'
end
end
Browsing to http://myhost/abc/ for the Rails2 app, brings up the page with no css, and the following error:
GET http://myhost/assets/application-asdasd.css 404 (Not Found)
I've tried using config.assets.prefix = '/abc' in the production.rb file but it didn't work. I've also tried different variations in the ngnix.conf file to no avail either.
Anyone know what I'm doing wrong, or missing?
UPDATE
I'm not quite sure why, but I was able to get this to (incorrectly) work using an #location instead of an upstream. But I had to move the assets folder from the Rails2 app to the Rails1 app. Not exactly ideal.
Changes to the server section:
location ~ ^/(assets)/ {
expires max;
add_header Cache-Control public;
access_log off;
}
location ~ ^/(abc)/ {
root /rails2/public;
try_files $uri/index.html $uri.html $uri #rails2;
error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
error_page 403 /403.html;
}
location / {
root /rails1/public;
try_files $uri/index.html $uri.html $uri #rails1;
error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
error_page 403 /403.html;
}
location #rails1 {
proxy_pass http://127.0.0.1:3000;
}
location #rails2 {
proxy_pass http://127.0.0.1:3030;
}
From a similar question: https://stackoverflow.com/a/3355589/417872
Have you tried this?
config.action_controller.relative_url_root = '/rails_app'
I would recommend googleing for how to correctly serve a rails app from a subdirectory. That's the real issue you're dealing with, and a quick search returned several pages of useful looking links.
I had a similar problem running Rails 4 on Nginx in production environment. The solution I found was to specify the root path for the asset location in nginx.conf:
location ^~ /assets/ {
root /home/rails/myapp/public;
gzip_static on;
expires max;
add_header Cache-Control public;
}
Hope this helps

Maintenance page with nginx for one domain_name among others

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/

How do I configure nginx to have a Rails app at a domain and WordPress at /blog/?

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; #

Resources