How to serve an api subdomain using apache, passenger, and rails? - ruby-on-rails

I created a subdomain like the following myapp.example.com and it works great ...has been. Now I want to build an API using rails for the app (rails itself) so I created the subdomain api.myapp.example.com. Currently the problem I'm getting is the api subdomain isn't getting routed to the rails app.
I tried adding the following to the apache conf file in /etc/apache2/sites-enabled/example.com.conf
# example.com.conf
ServerAlias *.myapp.example.com
I then restarted Apache, but still api.myapp.example.com wasn't being routed to rails application.

Ahhh, it ended being an easy fix
# example.com.conf
ServerAlias myapp.example.com api.myapp.example.com

Related

How to change the configuration file to deploy a rails app with apache? on a subdomain

I was given an url http://XXXXXX.XXXX.XXX/avrccalendar/
and was asked to deploy my rails app on it.
At the beginning, there was a static webpage index.html in the /www directory, which is nothing but a message and was deleted by me.
This is my first time to deploy a rails app and I set my .conf like this:
VirtualHost *:80>
ServerName XXXXXX.XXXX.XXX/avrccalendar
DocumentRoot /home/avrccalendar/calendar/public
RailsEnv production
/VirtualHost>
I set it up that way, because I think rails app creates dynamic content, thus I didn't put the app files in the /www directory. However, when I visit the website it still get the static webpage index.html.
I cannot find whers the configuration is that set the url to return that static webpage.
And i would like to know how I should set .conf to make it to visite my rails app.
I have already installed passenger. The environment is Ubuntu 14.04.
Any advice would be helpful. Thank you~!

Rails 4 in a subdirectory

I have a dream, that one day, my Rails 4 app can be served from /sub in production.
Requests for /sub and /sub/projects would simply look like / and /projects to the app. All assets would be served from /sub/assets.
But still, in development environment, everything can be run from the root of localhost:3000.
Regardless of the server behind (apache / nginx), how do I need to configure the rails app?
If I understand you correct:
You can place project on production server everywhere you want. You just need describe it in apache or nginx config file. For apache use DocumentRoot directive. For nginx use server -> root syntax.

How to move redmine to a sub-URI with nginx as a proxy

I want to put redmine (listening on localhost:3000 standalone passenger) behind nginx, serving from http://domain.com/redmine with this simple nginx config:
server {
location /redmine/ {
proxy_pass http://domain.com:3000/;
}
}
I rewrote redmine's config/environments.rb based on the instructions from this HOWTO, and redmine properly rewrites static asset URLs, but controller URLS are not rewritten, for ex. settings point to http://domain.com/settings instead of http://domain.com/redmine/settings.
How can I properly configure redmine to run behind nginx?
This is a pretty complicated thing to do. You wouldn't think so but it is. Every single redmine version that comes out has a different set of correct and incorrect ways of accomplishing this. For example, I have a working configuration with (nginx-1.4.1, unicorn, redmine-2.2.1) but now that I'm using (nginx-1.4.2, unicorn, redmine-2.3.3) that doesn't seem to work anymore. Here's some links that may be of use:
http://www.redmine.org/issues/11881
http://www.redmine.org/issues/12102

Ruby on Rails app in root directory?

Hey guys, new to rails, but I have found out how to create an app now through the shell but to create an app using rails appname would give me a url of http://url.com/appname/ but I want my app, to be within the route if you understand me, so it's just http://url.com/login/ or /signup or /play so on?
So does anyone have any ideas how to do this, or why you can't or I shouldn't? Anything really, thanks guys!
if you use passenger and apache, firstly in your apache conf file
<VirtualHost *:80>
ServerName myapp.local
DocumentRoot "/home/davit/myapp/public"
</VirtualHost>
DocumentRoot should be point to your app' s public folder.
And in public folder create a .htaccess file and write this:
PassengerEnabled on
RailsEnv development
Rails application is stored in some directory like appname but it doesn't appear in url path. In general you should configure your server (Apache, nginx, ...) to point to public folder in rails application. The only thing to do is to configure your server properly.
It depends on your hosting provider, with dreamhost, which I use, its part of the tools they provide to configure where do I want the application to be.
If you have to configure things yourself, you can still write your alias configuration or whatever your server uses to map to your rails application public/ folder.

Redmine doesn't work properly in Apache

I'm trying to get Redmine (a Ruby on Rails app) working. It works fine when started with ruby script/server webrick -e production, however, I'm having trouble getting it working in Apache with Passenger.
Accessing http://example.com/redmine returns the Redmine home page, but clicking any link (or even adding a / to the URL) results in a 404. According to the Rails log, a RoutingError occurs. For example, when opening the projects page: ActionController::RoutingError (No route matches "/projects.html" with {:method=>:get})
The Redmine directory is /var/www/localhost/htapps/redmine. I followed the documentation at http://www.modrails.org/documentation/Users%20guide.html#_deploying_a_ruby_on_rails_application (section 3.2), so there's a symlink at /var/www/localhost/htdocs/redmine pointing to ../htapps/redmine/public, and the Apache configuration contains DocumentRoot /var/www/localhost/htdocs and RailsBaseURI /redmine.
What is causing it to raise these RoutingErrors?
It looks like this issue was actually caused by the default .htaccess included with Redmine.
Redmine's .htaccess rewrites every request to end with .html. Redmine's routes expect .html-less requests.
Setting RewriteEngine to Off solved the issue for me.
http://ptspts.blogspot.com/2009/05/how-to-fix-railsbaseuri-sub-uri-with.html
The manual workaround (according to what is suggested on the pages above) is adding the line below to config/environments/production.rb:
config.action_controller.relative_url_root = '/redmine'
If not deploying to a Sub-URI and deploying using passenger, adding the rule RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] to your public/.htaccess also solves the issue. As that rule is IfModule-ed out in the default .htaccess.
Another option is to delete .htaccess if you're not using it (As an example you may be using it for additional layer authentication with AuthType Digest etc). It is not required when deploying with passenger.
Even if you will manage to run Redmine in suburi, redmine still will have issues.
Some pages won't be parsed and displayed correctly, if displayed at all.
This issue is almost one year old and indicated for next minor release. Btw dozen minor releases came out, but it's not yet fixed. FCGI mode does not support sub-URI.

Resources