how to deploy rails action as site root - ruby-on-rails

in routes.rb, I set a controller and a action as root, it works very well when I visit root in development mode.
now , I try to use nginx to hook rails app together, seemed nginx.conf need rails public folder which is not the root path set in the routes.rb.
index under public folder only can be a static html, how could I hook nginx with rails action as root?
Thanks for your answer!

nginx is only a webserver - have you installed something like Passenger as your app server to run your application in? It's perfectly normal to map the webserver to your public folder but then the application server will process the request and serve back your app for you

Related

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.

Trying to set up a simple nginx ruby on rails development. How do I run the app?

I am really struggling to understand this.
I have used PHP / Apache all my life but I just need to have a very basic setup of a Ruby on Rails app on an Nginx server for development.
I have set up an Ubuntu 12.04 server with Vagrant / VirtualBox.
I can see in the web browser the "Welcome to nginx!" message and there's a Ruby on Rails app installed on the server (tested with someone else and working on there server).
The Ruby on Rails application is in an /app/ folder and with these folders:
- assets
- controllers
- helpers
- mailers
- models
- observers
- uploaders
- views
Now, all I need to do is run the thing. Where is my index file?
Are there any other folders I should take note of? There's nothing I can see.
I've tried configuring sites-enabled but none of it makes sense. Surely it should be a simple case of getting my-domain.com to display the index file. Simple, surely? Which file in the /app/ folder am I trying to run?
For development you can use the built-in web-server with rails s in your project folder. It will runs your RoR app on 0.0.0.0:3000. Port can be changed with -p (rails s -p 80).
Read this guide to running rails on nginx using passenger:
Once Ruby on Rails is installed, go ahead and install passenger.
gem install passenger
...
Set the root to the public directory of your new rails project. Your
config should then look something like this:
server {
listen 80;
server_name example.com;
passenger_enabled on;
root /var/www/my_awesome_rails_app/public;
}
(Don't forget the /public after the rails root location!)

Ruby Passenger displays content from public instead of the app

I have a server in the cloud. I've set up a Linux machine with Apache2 + Passenger(with the apache module installed).
I've configured by the book, set up the VirtualHost as the Passenger instructions tell me to.
I've created a default Ruby on Rails project in "RubyMine"(on the local machine), synchronized it with the server.
Here is the project file hierarchy:
Since the instructions ask me to point in the configuration file to /projectFolder/public, I did so. If there is no index.html in the public folder, it throws me an error, if I create one it displays it when I access the link.
But when on the local machine I deploy it, it instead launches the app from app->views->layouts.
How to make it run on the remote server my ruby code? My ruby "app"?
First try:
sudo passenger-status
This should show you if passenger is loaded and the applications group. If that is all good, delete the index.html from /public and restart apache.

Ruby on Rails only showing what is in public folder

I am new to rails and have developed a simple rails application on my machine that works when hosted locally with WEBrick.
I understand that you need to delete index.html from the public folder and set the proper root in config/routes.rb to point to the controller you wish to be root, which I did with:
root :to => 'home#index'
(On the remote host)
When I have the index.html file in the public folder and go to mywebsite.com/myapp I see the page.
When I delete the index.html page from the public folder I get a 404 and my app does not run.
Any idea as to why my app is not running when I deploy it to the remote host?
If you set your root to home#index, then you need to have a view app/views/home/index.html.erb. The corresponding controller method would be def index, located in app/controllers/home_controller.rb.

Respond with index.html to directory request on nginx serving rails app

How can I make nginx or passenger respond with the index.html contained in the corresponding directory requested? For example I have a folder called media inside my public directory on my rails app, I want nginx to serve public/media/index.html when mysite.com/media of mysite.com/media/ is requested. I tried setting index index.html; inside my server directive in nginx conf, but it stopped serving my Rails app. I guess it's really simple I just couldn't find the solution on my own.

Resources