Rails action cable with apache 2.4 - ruby-on-rails

I am trying to get a chat application working using rails action cable and apache. I am trying to make this work https://github.com/ScotchSource/ActionCableUploading, but no luck just yet.
Apache config
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
# I have tried many different URI to be proxied, but still no luck
ProxyPass /test-app/cable ws://servername:7521/test-app/cable
ProxyPassReverse /test-app/cable ws://servername:7521/test-app/cable
Alias /test-app /var/www/test-app/public
<Location /test-app>
PassengerBaseURI /test-app
PassengerAppRoot /var/www/test-app
</Location>
<Directory /var/www/test-app/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
Made a few changes and tried different URLs in config.action_cable.url in environment/development.rb to point to the correct proxy in apache config.
I have read many blog posts and articles and tried different setups. Some people manage to make it work, but when I tried their solution it does not work. Any ideas/suggestions would be appreciate it.

Related

URL routing on Bitnami Google Compute Ruby on Rails

I am attempting to deploy the sample rails app: https://github.com/railstutorial/sample_app_rails_4 to the Google Compute Engine using Bitnami. I have followed the wiki instructions to do so from: https://wiki.bitnami.com/Infrastructure_Stacks/BitNami_Ruby_Stack#How_can_I_deploy_my_Rails_application.3f
But upon attempting to access the url for the site, it still does not direct to the Rails app
as you can see here: http://www.1234-ok-go.com (a domain I have purchased) it simply goes to the base Ruby Stack success page.
Even though I have setup the httpd-vhosts.conf to specifically target the Rails App:
<VirtualHost *:80>
ServerName 1234-ok-go.com
DocumentRoot "/opt/bitnami/apps/myapp/htdocs/public"
Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
</VirtualHost>
<VirtualHost *:443>
ServerName 1234-ok-go.com
DocumentRoot "/opt/bitnami/apps/myapp/htdocs/public"
Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
</VirtualHost>
How can this issue be alleviated and route the URL to my Rails app?
Bitnami developer here.
After you had created your httpd-vhosts.conf (the one you pasted) file under installdir/apps/myapp/conf/ you have to append this line to /installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf
Include "/installdir/apps/myapp/conf/httpd-vhosts.conf"
And then create this file: /opt/bitnami/apps/myapp/conf/httpd-app.conf to look something like this:
<Directory /installdir/apps/myapp/htdocs/public>
Options +FollowSymLinks
AllowOverride None
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
PassengerEnabled on
PassengerAppRoot "/installdir/apps/myapp/htdocs"
</Directory>
And finally, restart apache:
<installdir>/ctlscript.sh restart apache

Rails 3 + passenger conf file

I have been trying to install a rails app on a box that originally was used for multiple php applications. I installed passenger and created a conf file but I am confused about how it all works together.
What should my ServerName be if i want to access a Rails app? The box is a debian squeeze running apache2 with passenger module installed. Below is my conf file. I currently have to go to xxx.xxx.xxx.xxx/leoadmin/public to get the application to run properly. I have the following htaccess in the public directory. Which I think is unnecessary if my conf file is configured correctly.
I think my main issue is the misconfiguration of the conf file. I believe the conf file is being loaded but i don't understand why i still need the htaccess for me to see any action.
.htaccess
#PassengerEnabled On
PassengerAppRoot /var/www/leoadmin/
#Options -MultiViews
#PassengerResolveSymlinksInDocumentRoot on
#Set this to whatever environment you'll be running in
RailsEnv production
#RackBaseURI /var/www/leoadmin
vhost config
<VirtualHost *>
ServerName leoadmin
DocumentRoot /var/www/leoadmin/public
<Directory /var/www/leoadmin/public>
Allow from all
</Directory>
Alias /leoadmin /var/www/leoadmin/public
<Location /leoadmin>
SetEnv RAILS_RELATIVE_URL_ROOT "/leoadmin"
PassengerAppRoot /var/www/leoadmin
</Location>
ErrorLog /var/log/apache2/leoadmin-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/leoadmin-access.log combined
</VirtualHost>
I had nothing but pain and more pain trying to get this sorted a few months back, my configuration allows me to do sub URIs, so I'm not sure if that's what you want, but it'll be along these lines. I've never needed a .htaccess file for this setup:
NameVirtualHost *:80 <VirtualHost *:80>
ServerName www.test.co.uk
DocumentRoot /web/rails
<Directory /web/rails>
Allow from all
</Directory>
RailsBaseURI /test
RailsEnv development
<Directory /web/rails_projects/test/>
Options -MultiViews
</Directory>
For me /web/rails is a root directory, from there I have a number of symlinks to my /home/ directory where I store my projects. ServerName is whatever qualified name you're using for the machine that's going to be recognised.
(just in case, I'm running Passenger 3.0.9, and Rails 3.2.11)

Phusion Passenger + Apache 2 + Rails 3. Works on local network, not when accessed externally

The problem:
I have created a Rails project skeleton using rails new TestApp in the /var/www/ directory of my server. The Rails default index.html displays and works properly (i.e., you see the rails logo and when you click on "About your application's environment" you get a correct listing of the environment specifications used on the server) when I access the site from the same network on which the server is running. However, if I access the site from a machine on a different network than the server's, the page displays but I do not get the rails logo image, and clicking on "About your application's environment" results in the following error display on the page:
Not Found
The requested URL /TestApp/rails/info/properties was not found on this server
And that URL shouldn't be found, because it doesn't exist. However, TestApp/public/rails/info/properties does exist.
Configuration:
The site resides in /var/www/TestApp and I access it from a Sub-URI. I have created a symbolic link in /var/www/ called rails as follows: rails -> /var/www/TestApp/public, such that the project can be accessed from www.mydomain.com/rails. My Apache configuration is the following, note that I've omitted,changed, or shortened some parts within the <VirtualHost> tag for brevity:
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/ex$
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p194/ruby
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName www.mydomain.com
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>
.
.
.
#Rails Configuration
RailsBaseURI /rails
RailsEnv development
PassengerUserSwitching off
PassengerDefaultUser www-data
<Directory /TestApp/public>
Options FollowSymLinks -MultiViews
AllowOverride All
Allow from all
</Directory>
#End Rails Configuration
.
.
.
</VirtualHost>
A couple of things: the appropriate folders are owned by www-data with the appropriate permissions as defined by the Passenger documentation. When setting up the symlink and RailsBaseURI settings I followed the Passenger documentation.
I guess I'm at a loss here since everything seems to be working when accessing the website from the same network on which the server resides. I'm not sure why things aren't working out when accessing the site from a different network, but I feel like paths to certain resources/assets (like the rails logo) aren't resolving properly. Perhaps my symlink is configured inappropriately, or something is wrong with my Apache configuration?
Any help would be appreciated.
The issue of a somewhat broken default Rails page is not totally abnormal, it turns out.
I removed the default Rails page and replaced with another page that included some Rails code and everything worked like a charm.

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

Passenger: RailsBaseURI case sensitive?

I used Passenger to deploy a RoR app to a sub URI on my domain. The problem I'm facing is that the sub URI seems to be case sensitive. Navigating to http://mydomain.com/RailsApp resolves fine. However, if I go to http://mydomain.com/railsapp, http://mydomain.com/railsApp, or any other variation, I get a 404 error. How can these requests using different casings get resolved correctly?
Here is my Apache configuration file:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /www/mydomain/public
<Directory "/www/mydomain/public">
RailsEnv "production"
Order allow,deny
Allow from all
</Directory>
RailsBaseURI /RailsApp
<Directory "/www/RailsApp/public">
RailsEnv "development"
Options -MultiViews
</Directory>
</VirtualHost>
Any help is much appreciated. Thanks!
You could look into using mod_rewrite and matching it case insensitive there.
Some links to get you started :)
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
http://httpd.apache.org/docs/2.2/misc/rewriteguide.html
Thanks ba for pointing me in the right direction.
I did some research and found the mod_speling module. This not only makes the URL case-insensitive but also checks for spelling errors.
To enable mod_speling:
sudo /usr/sbin/a2enmod speling
sudo /etc/init.d/apache2 force-reload
sudo /etc/init.d/apache2 restart
To use mod_speling, include the directive CheckSpelling on in your virtual host section:
<VirtualHost *:80>
CheckSpelling on
...
</VirtualHost>

Resources