Error Deploying Rails Application - ruby-on-rails

I had issues when I tried to deploy my Rails site
when i start mongrel and start my app and rewrite and start with Apache
the application has ben displayed
but when i link to http://myapp.com/account/login
Not Found
The requested URL /account/login was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
when i try default myapp.com:12007/
it was normal, i can link
what is the problem ?

just for information
the problem is # .httaccess file
# folder public_html/
just need edited like this :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^myapp.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.myapp.com$
RewriteRule ^.*$ "http\:\/\/127\.0\.0\.1\:12007%{REQUEST_URI}" [P,QSA,L]

Try add NameVirtualServer *:12007 to the end of your apache2.conf file

Related

Rails - .htaccess not forcing users to use https

I want user to only be able to access the https version of the site. I figured out that a way to do this is with a .htaccess file. I've have added the SSL cert and thats all working fine.
I made the .htaccess file and added the following code in it (replacing 'example' with the domain name)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
I deployed it and visited http://example.com/ and it loaded just fine as http.
I dont know if because its a rails app that I might need to put the .htaccess file in the public folder, or if there is more I need to do. But from what I read this should work.
I'm using google cloud platform to host my site, and I cant find the VM server type so maybe its not the right server type to run .htaccess files on?
I'm hoping someone here knows how to get this working.
With .htaccess try the following:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
However, with Rails you can use the following in your environment config:
config.force_ssl = true

How can I force a URL to have "www." no matter what?

I'm using Joomla 1.5 and Virtuemart 1. It might seem like a weird question but I need my URL to have "www." written in the URL at all times. If the URL doesn't have "www." then the cart functions don't work. If it does have it, then it does work.
Is there a way I can force this? I am using Parallels Plesk 10.3.1 if I can do it on there.
if your server is running on apache, you can add a .htaccess file to your root webdirectory with the following content:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

http to https redirect on openshift rails app

I want my rails 4.0 app on Openshift Online to serve content only over https.
There is a guide which tells to use a .htaccess in the web-root:
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
I followed the guide and put a .htaccess file with the directive in my app-root/repo directory on the openshift cartridge, but nothing happens. The guide talks about a web-root dir. What is the web-root directory of a rails app, or what is a web-root directory on openshift? And is there another way to establish http to https redirect for rails on openshift?
I was in a similar situation as you (but wanting to redirect depending on the Accept-Language http header), and could not find the place where to put the .htaccess on an OpenShift ruby cartridge.
Tentative with .htaccess
I tried to put the .htaccess file in the app-root/repo, app-root/runtime, app-root/data, the ~/ruby/ directories with no success..
So I ended up doing the redirections from the rails app
A solution for your case through Rails
If you want to enforce SSL for all your application you can simply set config.force_ssl = true in your config/application.rb file. Another common use case is to enforce SSL only for your production environment, thus instead of putting this configuration in your general application.rb file, you can set it in your config/environments/production.rb.
In case you need to enforce SSL only for specific controllers, you could also just call the force_ssl method in the top of your controller as:
class MyController < ApplicationController
force_ssl
[...your actions..]
end
My problem & solution through Rails
I wanted to add this .htaccess
RewriteEngine On
RewriteCond %{HTTP:Accept-Language} ^pt [NC]
RewriteRule ^/$ /pt/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^/$ /fr/ [L,R=301]
RewriteRule ^/$ /en/ [L,R=301]
And finally had to do it in the config/routes.rb config file of rails with
get '/', to: redirect { |path_params, req|
"/#{req.env['HTTP_ACCEPT_LANGUAGE'].scan(/^(?:pt|fr)/).first || 'en'}" }
Any help from the OpenShift team to explain where to put a .htaccess for a Ruby cartridge is still very welcome!
There is one solution for Ruby 1.9 for OpenShift 2 with steps for terminal:
cd your_ruby_git_project_folder/public/
vi .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
</IfModule>
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
cd ..
git add . -A
git commit -m 'message'
git push

.htaccess multiple domains in public_html with rails

I'm using a shared hosting account which allows me to host multiple domains, but they must all be within the same public_html folder. The "add-on" domains seem to work just fine, but I'm trying to get my primary domain to work properly. It is a Rails app, being hosted through Phusion Passenger.
My current mapping is as such:
primarydomain.com ---> ~/public_html/primarydomain/
addondomain1.com ---> ~/public_html/addondomain1/
addondomain2.com ---> ~/public_html/addondomain2/
My .htaccess is as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$
RewriteCond %{REQUEST_URI} !^/primarydomain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /primarydomain/$1
RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$
RewriteRule ^(/)?$ primarydomain/ [L]
which is based on recommendations from the hosting company. I don't worry with the add-on domains because the host automatically links those up properly through other configuration tools. I just need to make the primary one be hosted from a subdirectory.
The problem is that when I try to set up my rails app so that it maps like such
http://primarydomain.com --> ~/public_html/primarydomain/ --> ~/rails_apps/primary/public
It always fails giving me the following error in the log file:
Started GET "/primarydomain/" for 11.22.33.44 at 2014-01-11 21:58:29 -0700
ActionController::RoutingError (No route matches [GET] "/primarydomain"):
...
Any thoughts to how to resolve this?

Tell Rails to ignore particular URL and let Apache handle

I have a rails app running on my Apache server via Passenger.
Occassionally I am using some PHP scripts for the website, and have placed them in the public directory.
When I go to /php/ I want Apache to handle the request with the PHP parser and have rails ignore it.
Currently I can go to /php/index.php and it works fine. However I need /php/ to work as well but rails keeps looking for the controller to handle it.
I have a feeling this is something to do with apache rewrite rules, but I cant figure it out.
I have used
RewriteEngine On
RewriteRule ^php - [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
in the /php/.htaccess file but this doesnt work. I still get the page not found error by Rails.
I think you can do this in your Passenger app's main Apache config file - something along the lines of this
<Directory "/.../myapp/php">
PassengerEnabled off
AllowOverride all
</Directory>
inside your VirtualHost block should do the trick (of turning Rails off, at least - turning PHP on is up to you!).
My answer is based off the ModRails Apache documentation - see section 5.6 for more on the PassengerEnabled command.

Resources