In Server Images are not responding in rails3 - ruby-on-rails

I am having issue that with this alias when I am pointing to a server at that time images are not showing.
My configuration of server for the application is
Alias /questions /app/xyz/public
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p327#abcd/ruby
#RailsBaseURI /beingme
RailsBaseURI /questions
<Directory /app/xyz/public>
RailsEnv production
Options Indexes FollowSymLinks -MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Please provide me the solutions.

You have to define one more Alias for assets
Alias /assets /app/xyz/public/assets
It will work for you, I hope.

Related

RackEnv not respected when using route helpers from model

Running Rails 3.2.13 on Passenger for Apache. My vhost:
<VirtualHost *:80>
ServerName server
DocumentRoot /srv/http
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
RackEnv test
RackBaseURI /rails_app
<Directory /srv/http/rails_app>
Options -MultiViews
</Directory>
</VirtualHost>
Works great. Only problem is that I'm using the route url helpers in a model, like so:
# egg.rb
def to_exhibit
return {
:edit_path => Rails.application.routes.url_helpers.edit_egg_path(self)
}
end
When rendering URLs in views, the sub-URI is used as I'd expect it to be, but when accessing the URL helper from within a model, it's discarded and the paths are always relative to the root.
From eggs_controller.rb:
edit_egg_path(1000) --> /rails_app/eggs/1000/edit
From some_model.rb:
edit_egg_path(1000) --> /eggs/1000/edit
Should this work as I expect it to? I don't mind manually fixing this at all, but I'm stumped as to where to find the value of the RackBaseURI so I can insert it manually, if it exists. I'd prefer not to manually define it again in some environment conf since Rails must know about it already.

Seeing the document root instead of my rails app running, Ubuntu VPS with Phusion Passenger

I am running ubuntu on my VPS and have installed apache as well as phusion passenger to deploy my rails apps with. I went through the setup for phusion passenger and everything installed just fine. I edited the apache configuration files and have appended the information below. I have also made sure that the Virtualhost is not being overridden the default host and when I changed that and refreshed a browser I was brought to the public directory of my rails app instead of having the rails app being executed. Any help would be appreciated.
additions to /etc/apache/apache2.conf
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-3.0.8/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.8
PassengerRuby /usr/bin/ruby1.8
PassengerDefaultUser www-data
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/bodylabel/globify/public
<Directory /home/bodylabel/globify/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
/etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
/etc/host.conf
# The "order" line is only used by old versions of the C library.
order hosts,bind
multi on
Just ran sudo passenger-status and got back the following:
*** Cleaning stale folder /tmp/passenger.44591
*** Cleaning stale folder /tmp/passenger.44300
*** Cleaning stale folder /tmp/passenger.44372
*** Cleaning stale folder /tmp/passenger.44200
*** Cleaning stale folder /tmp/passenger.21157
*** Cleaning stale folder /tmp/passenger.43944
*** Cleaning stale folder /tmp/passenger.21589
*** Cleaning stale folder /tmp/passenger.44878
ERROR: Phusion Passenger doesn't seem to be running.
the obligatory dumb question, but, did you restart apache?
Also, although this probably isn't the source of your problem, you may want to use the debian-esque method of deploying sites here and drop that virtualhost config into /etc/apache2/sites-available and run a2ensite to activate it.
There's probably a similar construct in place for modules-available and modules-enabled, where you might put that passenger code, rather than in apache2.conf.
You have two VirtualHost with the ip/port name *:80. Apache will do one of two things here. If you have a matching NameVirtualHost directive in your config then it will look for ServerName (and ServerAlias) directives within those two virtual host sections, and if the incoming request matches those server names/aliases then it will serve that virtual host.
Otherwise, it will serve the first VirtualHost block that is defined first in your configuration files. So, which one is being served will depend on the order that sites-enabled/000-default is included relative to the location of the VirtualHost section in apache2.conf

Frontend pages giving 404 with symfony and apostrophe

I thinks this question might be on the edge of having to go on serverfault. However, as I'm not sure about the cause of the problem, I'll ask the question here.
I Have a Symfony installation with 2 apps: frontend and backend
On the frontend I run apostrophe cms and in the backend I have some modules from the doctrine admin generator.
Everything works fine local. However, on my production server, every frontend page after http://mydomain.com/ gives a 404 error. The weird thing is that http://mydomain.com/backend/ works fine. I'm not sure if its my apache config (seeing as /backend/ does work) but I'll paste it here, just to be sure. This is what I have in sites-available/default:
<VirtualHost *:80>
DocumentRoot "/mysfproject/web"
DirectoryIndex index.php
<Directory "/mysfproject/web">
AllowOverride All
Options Indexes FollowSymLinks MultiViews
Allow from All
</Directory>
ErrorLog /var/log/apache2/error.log
Alias /sf /mysfproject/lib/vendor/symfony/data/web/sf
<Directory "/mysfproject/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Any help would be greatly appreciated!
Turns out mod_rewrite was disabled. Fixed it by doing sudo a2enmod rewrite

Setting up Rails app on Apache with passenger - Rails doesn't seem to load

I am trying to set up Rails on a Ubuntu instance by following along with documentation such as https://help.ubuntu.com/community/RubyOnRails. I am trying to set up the app from the Rails Getting Started page here: http://guides.rubyonrails.org/getting_started.html.
What I have done so far:
Installation of Ruby/RubyGems/Rails through RVM and GEM (this installed Ruby 1.9.2 and Rails 3.0.7)
Installation of the mysql and mysql2 module (latter which didn't work)
Creation of rails app (blog app as tutorial is instructing)
Sym linking of /home/me/www/blog/public/ from /var/www/blog/
Creation of DB through rake
Installation of passenger module for Rails execution in Apache
Running of passenger-install-apache2-module to configure Apache
Deletion of public.html file from public/ rails app folder so that my controller/view can fire
Configuration of sites-available files for virtual hosts
Configuration of Rails routing
I believe it is the last two steps that are tripping me up, partly due to lack of familiarity with Apache and Rails (I am new to both).
In my virtual host file I am trying to point to the blog public dir in /var/www/blog. For my Rails route I have root :to => "home#index" as instructed.
When I browse to the http:// url I should normally be seeing my "Hello, Rails!" page per section 4.3 of the Getting Started guide, however all I see is the directory listing from Apache. Static pages work but not Rails processing.
At this point I am unclear if the passenger module is even doing anything or where to look for any evidence of what is happening. I tried various things like running the Rails app off a different virtual host called "blog" at http:///blog and the routing worked (static pages and all) but no Rails as above.
Update: after playing around some more, I now get a new error message (404):
Not Found
The requested URL /dispatch.cgi was
not found on this server.
I have since determined that this cgi 404 was caused by a rewrite rule I had added to .htaccess from guidance from the help.ubuntu.com page I pointed out above. Looks like it wasn't necessary or applied to an older version of Rails. The inconsistencies in instructions when looking up help online is disorienting! Removing the file leaves me with the previous problem though.
Here's the entry in the Apache log that I believe correlates with the first error. Although I am no longer getting this error it seems, may be related to something else I was trying before...
[Fri May 27 22:49:41 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9 with Suhosin-Patch Phusion_Passenger/3.0.7 configured -- resuming normal operations
[Fri May 27 22:51:18 2011] [error] [client 192.168.1.141] File does not exist: /var/www/blog/rails, referer: http://192.168.1.138/blog/
Here's the most recent entry with the 404 on the cgi thing:
[Sat May 28 08:01:18 2011] [error] [client 192.168.1.141] File does not exist: /var/www/blog/dispatch.cgi
What could I be missing? Thanks!
Additional details as requested. Apache sites file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/blog/
RailsEnv development
# <Directory />
# Options FollowSymLinks
# AllowOverride None
# </Directory>
<Directory "/var/www/blog/">
Options Indexes FollowSymLinks -MultiViews +ExecCGI
AllowOverride All
Order allow,deny
allow from all
# AddHandler cgi-script .cgi
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Another update: I was able to get it working, finally, by using a top level DocumentRoot (/var/www) and basing my Rails app off that using RailsBaseURI. This maps to the "Deploying to a sub URI" section of the Phusion Passenger instructions. It is used as http:///blog which is not really what I wanted to get, but it's kind of irrelevant as I am using this just to learn Rails in a virtual. I will need to go and work on getting it working as a top level app again sometime later. Here's my current (final) VirtualHost file for reference:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/
RailsEnv development
<Directory /var/www/>
Options FollowSymLinks
AllowOverride None
</Directory>
RailsBaseURI /blog
<Directory /var/www/blog/>
Options Indexes FollowSymLinks -MultiViews +ExecCGI
AllowOverride All
Order allow,deny
allow from all
# AddHandler cgi-script .cgi
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Deploying a Ruby on Rails application
Suppose you have a Ruby on Rails
application in /webapps/mycook, and
you own the domain www.mycook.com. You
can either deploy your application to
the virtual host’s root (i.e. the
application will be accessible from
the root URL, http://www.mycook.com/),
or in a sub URI (i.e. the application
will be accessible from a sub URL,
such as
http://www.mycook.com/railsapplication).
Deploying to a virtual host’s root
Add a virtual host entry to your
Apache configuration file. Make sure
that the following conditions are met:
The virtual host’s document root must
point to your Ruby on Rails
application’s public folder.
The Apache per-directory permissions
must allow access to this folder.
MultiViews must be disabled for this
folder.
For example:
<VirtualHost *:80>
ServerName www.mycook.com
DocumentRoot /webapps/mycook/public
<Directory /webapps/mycook/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
You may also need to tweak your
file/folder permissions. Make sure
that the following folders are
readable and executable by Apache:
this public folder.
the application’s config folder.
all parent folders. That is, /webapps/mycook and /webapps must also
be readable and executable by Apache.
Then restart Apache. The application
has now been deployed.
Read the whole docs here
Double check to make sure passenger is loading your application by typing
sudo passenger-status
This will show you an error if passenger isn't loaded or the below if it is. Note the part where it shows you which application or applications it has loaded and what the current uptime is:
----------- General information -----------
max = 6
count = 1
active = 0
inactive = 1
Waiting on global queue: 0
----------- Application groups -----------
/home/rourkem/public_html/evecord.com/current:
App root: /home/rourkem/public_html/evecord.com/current
* PID: 18976 Sessions: 0 Processed: 5 Uptime: 23m 55s
Be sure to delete the file index.html from the public directory of your application.

Having trouble setting up Apache for SSL with mongrel and rails 3 in development on ubuntu

I'm trying to setup apache2 so that I can try ssl in development on my rails 3 app on ubuntu.
The rails app works, except for https where in Fire Fox i get:
The connection was interrupted
The connection to localhost:3000 was interrupted while the page was loading.
In the console i get:
Thu Oct 14 15:56:28 +1100 2010: HTTP parse error, malformed request (127.0.0.1):
#<Mongrel::HttpParserError: Invalid HTTP format, parsing fails.>
Thu Oct 14 15:56:28 +1100 2010: REQUEST DATA: "\200U\001\003\000\000<\000\000\000\020\000\000\210\000\000\207\000\0008\000\000\204\000\0005\000\0009\000\000E\000\000D\000\0003\000\0002\000\000\226\000\000A\000\000\004\000\000\005\000\000/\000\000\026\000\000\023\000\376\377\000\000\n\000\000\377[������-V\214�e\277P-"
---
PARAMS: {}
---
I get the above console error whether Apache is running or not when using https. Which makes me think https localhost:3000 requests are never passing through Apache and instead going straight to mongrel which can't handle ssl.
Apache is working because if I go to http://localhost I get the default 'It Works' web page. I'm pretty sure the self signed certificates I created are also fine because going to https://localhost brings up the page in firefox asking if you trust the site and also lets me see the details of the certificate.
I've done a heap of googling and I've read through and tried a bunch of guides but many of them are a few years old and possibly out of date.
I ended up uninstalling apache2 and then reinstalling following this ubuntu guide https://help.ubuntu.com/10.04/serverguide/C/httpd.html It has a section on https configuration which I did and it creates this file -> /etc/apache2/site-available/default-ssl. It looks like this
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/ssl_access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
# Used by Rails. Mentioned in all the Rails SSL tutorials.
RequestHeader set X_FORWARDED_PROTO "https"
</VirtualHost>
</IfModule>
All I modified in there is the certificate and key locations, made it
<VirtualHost *:443>
instead of
<VirtualHost _default_:443>
and added the RequestHeader set X_FORWARDED_PROTO "https" line at the end as all the guides said to do. I'm not sure what else needs to be changed. At one point I did try setting the DocumentRoot to the public folder of my rails app but it didn't make a difference.
Apache restarts fine and there are no errors in the log.
I'm sure I must be really close to having it working but I've spent many hours over many days and just can't figure it out. My best guess is that I have something wrong or missing in the apache config file above.
My Questions are:
How do I know if the requests are actually going through apache?
If its not why is the https ssl request going through to mongrel and not being handled by apache?
What do I need to do to get it working?
I stuffed around for ages and still couldn't get it working with just apache so ended up following parts of this ubuntu rails guide and installing Passenger. Passenger was nice and quick to install and best of all https works now in development.
I guess I should put virtualHost *.80 in default and virtualHost *.443 in default-ssl but anyway this is what my sites-available/default-ssl file now looks like(store = rails app name):
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/daniel/www/store/public
<Directory /home/daniel/www/store/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName localhost
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
RequestHeader set X_FORWARDED_PROTO 'https'
DocumentRoot /home/daniel/www/store/public
<Directory /home/daniel/www/store/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
my httpd.conf file looks like this with settings for passenger and running rails in development mode using development database:
ServerName localhost
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.0/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.0
PassengerRuby /usr/bin/ruby1.8
RailsEnv development
RackEnv development
I'm still not 100% sure on how all the ports work but I'm guessing by using http://localhost:3000 the 3000 bit makes it go direct to mongrel and not through apache and therefore why the ssl never worked before. With apache and passenger setup as above I now go to http://localhost or https://localhost and it goes through apache and now works.

Resources