Sorry, this question may have already being answered, but I can't find the answer that will help me.
My situation is like this. We have a interal server, say called "helper.local.company" We currently use it to run a Rails Application. To get there a user just types "helper.local.company/ror_app1_route"
I would like to now install another app on to the server and then alloy the users to only type helper.local.company/ror_app2_route to get to the new app.
my current nginx conf file looks like this:
server {
listen 80 default_server;
server_name helper.local.company;
root /var/www/apps/ror_app1/current/public;
passenger_enabled on;
rack_env production;
}
What would I need to change or add inorder to allow the two rails apps to work with out having to use sub-domains?
Thanks
what keyword you need is 'passenger_base_uri'
reference from:http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_rails_to_sub_uri
The following is a simple example
Suppose that you already have a server virtual host entry:
http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
}
...
}
And you want your Ruby on Rails application to be accessible from the URL http://www.phusion.nl/rails.
To do this, make a symlink in the virtual host’s document root, and have it point to your Ruby on Rails application’s public folder. For example:
ln -s /webapps/mycook/public /websites/phusion/rails
Next, set passenger_enabled on and add a passenger_base_uri option to the server block:
http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
passenger_enabled on; # <--- These lines have
passenger_base_uri /rails; # <--- been added.
}
...
}
Then restart Nginx. The application has now been deployed.
You can deploy multiple Rails applications under a virtual host, by specifying passenger_base_uri multiple times. For example:
server {
...
passenger_base_uri /app1;
passenger_base_uri /app2;
passenger_base_uri /app3;
}
Related
I'm using nginx with passenger and I wanted to ask, how to create rails app, without showing app name in domain.
Currently I know how to setup nginx configuration with domain like this:
domain.com/app_name
and in the routes file when I create root 'welcome#index'
I still have to type domain.com/app_name to view my controller, but how to make it display welcome controller when the domain is simply domain.com
my nginx configuration looks looks this:
server {
listen 80 default_server;
server_name domain.com;
root /home/username/rails;
location ~ ^/app_name(/.*|$) {
alias /home/username/rails/app_name/public$1; # <-- be sure to point to 'p$
passenger_base_uri /app_name;
passenger_app_root /home/username/rails/app_name;
passenger_document_root /home/username/rails/app_name/public;
passenger_app_env development;
passenger_enabled on;
}
}
when I try to comment out #passenger_base_uri /app_name I got 403 ERROR code.
Any help would be appreciated.
You need to remove the location block, alias, passenger_base_uri, passenger_app_root, and passenger_document_root. Change root to your Rails public directory too. It should look like this:
server {
listen 80 default_server;
server_name domain.com;
root /home/username/rails/app_name/public;
passenger_app_env development;
passenger_enabled on;
}
Try to follow this example of this production nginx config, which also includes some best practices for configuring your server: https://gist.github.com/mikhailov/711913
In all the tutorials one may come across for setting up X-Accel-Redirect for nginx, there is always a bit about indicating a certain location is private, like so:
location /protected/ {
internal;
root /some/path;
}
The files I'm sending to my users are in RAILS_ROOT/private_uploads. This is not inside the public folder, meaning that there are no URLs that point to directly to the files in this folder.
So am I correct in assuming I can ignore that bit of nginx config for my setup? If not, what config would I need?
I'm using Passenger, btw, and my config is really basic:
server {
listen 80;
server_name mydomain.com;
root RAILS_ROOT/public;
passenger_enabled on;
}
I'am using Phusion-passenger and nginx to deploy my rails application, when i goto my server IP-Address i am able to access my rails application, but i cant access it when i go to the domain name. my configuration file looks like this;
server {
listen 80;
server_name my_domain.com;
passenger_enabled on;
root /home/user/rails_app/public;
}
i have tried configuring my nginx.conf in so many ways but it wasn't accessing the domain name. i also created a symbolic link to my application root folder like this
ln -s /opt/nginx/conf/sites-available/rails_app /opt/nginx/conf/sites-enabled/rails_app
i also tried doing this
ln -s /home/user/rails_app/public /home/user/rails_app
i updated my nginx.conf file to look like this also
server {
listen 80;
server_name my_domain.com www.my_domain.com;
root /home/user/rails_app/public;
passenger_enabled on;
passenger_base_uri /rails_app;
rails_env production;
}
You can rename the nginx config file for this app to the domain name, I guess it will help you in the future.
For the domain redirect, you need a DNS server (like Bind). If you're using a VPS server (like Linode, Webbynode or correlated), they provide you a structure to do that without installing a DNS server, it's very simple.
Besides that, your configuration is ok.
If you need some tunning, check this out.
I need to have redmine running in combination with nginx, phusion passenger and mysql. Because of the project requires several instances of redmine, which should be realized using different rails_env, I tried to set them in the different server vhosts with nginx.
Example of one vhost:
server {
listen xxxx;
server_name redmine.xxxxx;
root /xxxxx/redmine/public;
passenger_enabled on;
rails_env production;
}
Same goes for the other server vhost, but there server_name is matched to the other domain and rails_env set to internal.
The problem is, that nginx just uses one of both rails_env for both redmine instances, not one for each. Any advice how to use different rails_env with the same application, nginx and phusion passenger?
Thanks
I think you're having the same problem I had. You want to use the same physical directory to host the application instances but you want to interact with the app under different environments (development/production) by using different DNS entries (redmine.development / redmine.production)???
The problem is that passenger recognizes the incoming request as using the rails app found in the directory above root. If you're using the same literal reference for root in multiple nginx configs, passenger will forward the request to the single running instance found in root. i.e., if you start up your development application first, then try to access production via redmine.production, you'll end up interacting with the development environment. However if you start up your production app first, then try to access redmine.development, you'll end up interacting with production.
The answer is to symlink your app's directory for every environment you want to run. Passenger only looks at the literal path to root - if it doesn't match a currently running instance, it'll spawn a new one.
ex.)
Physical root is ~/rails_apps/myserver (where myserver contains app, public, etc.)
Create a symlink called ~/rails_apps/dev.myserver to ~/rails_apps/myserver and another one called ~/rails_apps/pro.myserver to ~/rails_apps/myserver.
Now inside your nginx config, use the symlink locations to the public folder as root.
ex., if symlink /home/user/rails_apps/[dev|pro].redmine points to /home/user/rails_apps/redmine)
server {
listen xxxx;
server_name redmine.development;
root /home/user/rails_apps/dev.redmine/public;
passenger_enabled on;
rails_env development;
}
server {
listen xxxx;
server_name redmine.production;
root /home/user/rails_apps/pro.redmine/public;
passenger_enabled on;
rails_env production;
}
nginx passenger doesnt follow symlink of .../app/public directory many time
because it expect it to be a directory not file
However you can use PASSENGER_APP_GROUP_NAME directive.
like this:-
server {
listen xxxx;
server_name redmine.xxxxx;
root /xxxxx/redmine/public;
passenger_enabled on;
rails_env production;
passenger_app_group_name devlopment;
}
server {
listen xxxx;
server_name redmine.xxxxx;
root /xxxxx/redmine/public;
passenger_enabled on;
rails_env production;
passenger_app_group_name production
}
I want to run the same Rails 3 app at urls: davinci.local.dev:8081 davinci.testing.dev:8082 and with environments development and testing, respectively.
I am using Nginx and passenger. My first attempt was:
server {
listen 8081;
server_name .davinci.local.dev;
root /Users/Nerian/NetBeansProjects/DaVinci/DaVinci/public;
passenger_enabled on;
rails_env development;
#rails_env development
}
server {
listen 8082;
server_name .davinci.testing.dev;
root /Users/Nerian/NetBeansProjects/DaVinci/DaVinci/public;
passenger_enabled on;
rails_env test;
#rails_env development
}
Yet when I browse to said urls, I get to the same deployment. If I first request the testing one, then it is that the app that is served always, whether I browse to davinci.local.dev or davinci.testing.dev. If I first request the development one, then it is that one which is served always.
Both deployments are using the same root app. Is there a way to make this works?
The objective is to serve the same app at different ENV in different domains.
I had a similar problem. I wanted a Rails application (named apparat) to have two nginx instances: example.eu for english version of the site and example.ee for estonian version. They share exactly the same functionality, so it makes sense to have just one code base for it (but I do have to make sure static assets like user-uploaded images won't collide).
server {
listen 80;
server_name example.eu;
root /home/apparat/public;
passenger_enabled on;
rails_env apparat_eng;
}
server {
listen 80;
server_name example.ee;
root /home/apparat/public;
passenger_enabled on;
rails_env apparat_ee;
}
However, similar to above, if I accessed example.ee, I got the example.eu instance of my Rails app. Possibly some quirk in nginx / passenger?
Anyway I got around by making an arbitrary symlink to /home/apparat, for instance
ln -s /home/apparat /home/apparat_eng
ln -s /home/apparat /home/apparat_ee
and changed the nginx config respectively
server {
listen 80;
server_name example.eu;
root /home/apparat_eng/public;
passenger_enabled on;
rails_env apparat_eng;
}
server {
listen 80;
server_name example.ee;
root /home/apparat_ee/public;
passenger_enabled on;
rails_env apparat_ee;
}
So I'm able to trick nginx into thinking these are different directories.
I took a different approach. The development server is served by nginx using passenger while the testing server is started on demand when using rake spec:acceptance.
So nginx.conf is:
server {
listen 8081;
server_name .davinci.local.dev;
root /Users/Nerian/NetBeansProjects/DaVinci/DaVinci/public;
passenger_enabled on;
rails_env development;
#rails_env development
}
Just that.
And in spec/support/custom_env.rb
Capybara.run_server = true
Capybara.app_host = 'http://davinci.testing.dev:8082'
Capybara.server_port = 8082
And that's the magic.