Host an app at home location of Shiny server - shiny-server

I installed my Shiny server and it is working fine with multiple app under this directory:
/srv/shiny-server/app1
/srv/shiny-server/app2
I can use www.mydomain.com/app1 to access my app.
But when I use www.mydomain.com it shows the default shiny server app with the example app.
All I want is when I go to www.mydomain.com I can see app1, how can I make that happen?
Thank you

As the other answer mentioned, you can edit the locationconstruct of /etc/shiny-server/shiny-server.conf.
Remove or comment out the site_dir and directory_index lines. Leave the log_dir line -- a log_dir is required within your first location construct. Add an app_dir line with the path to your app.
This works with the sample apps:
1) Remove the index.html file from /srv/shiny-server/
2) Edit the location section of /etc/shiny-server/shiny-server.conf to look like this:
location / {
# Host app at base directory
app_dir /srv/shiny-server/sample-apps/hello;
# Log all Shiny output to files in this directory
log_dir /var/log/shiny-server;
}
}

from: http://docs.rstudio.com/shiny-server/
modify your /etc/shiny-server/shiny-server.conf
server {
...
# Define the location '/specialApp'
location /specialApp {
# Run this location in 'app_dir' mode, which will host a single Shiny
# Application available at '/srv/shiny-server/myApp'
app_dir /srv/shiny-server/myApp
}
# Define the location '/otherApps'
location /otherApps {
# Run this location in 'site_dir' mode, which hosts the entire directory
# tree at '/srv/shiny-server/apps'
site_dir /srv/shiny-server/apps;
}
...
}

Related

How to setup nginx on devilbox to use nginx global variable mapping with php-fpm

I want to setup devilbox to run my local Magento multistore setup.
I use nginx as webserver
I need different Subdomains (no problem with devilbox and nginx.yml file in project)
I need different PHP Version (no problem with devilbox)
I need a nginx-global variabe mapping like
map $http_host $MAGE_RUN_CODE {
### Local
kkrieger.develop first_code;
subdomainA.kkrieger.develop second_code;
subdomainA.kkrieger.develop third_code;
### Default
~* default;
}
map $http_host $MAGE_RUN_TYPE {
~* store;
}
to use these variables in my vhost config for php:
fastcgi_param MAGE_RUN_CODE $mage_run_code;
fastcgi_param MAGE_RUN_TYPE $mage_run_type;
I tried to achieve this via nginx.yml file in my project but this is only template for vhosts
After that I created an additional .conf file in PATH_TO_DEVILBOX/cfg/nginx-stable/mapping.conf with content in it. But it seems that this does'nt work, too.
My current state:
- myproject.conf will not be generated
- devilbox says, that there's no valid DNS record for this domain in /etc/hosts - but it is.
How could I solve this?

Hosting Rails app on Thins, Nginx on a sub uri, behind a reverse proxy

Background
For my work, we have two different networks, the developers network, and the general company network. I need to expose the rails app to both, running under a sub uri so that the people on the general network can get to the app from foo.bar.com/{app_name}, and on the developer network from http://{server_name}.{dev_network}.dev/{app_name}. Sadly, we are not allowed to use Passenger, as this is an enterprise application.
Currently, I have the app running on a sub uri, and able to be accessed from both networks, but I am running into errors. I will list the errors I am seeing, then the nginx config I have created, as well as the rails_app config to work with the sub uri.
Problems
Going to {app_name}/foo/1 - any images on page are being fetched from {app_name}/foo/{app_name}/assets...... This is only happening for the show pages of the RESTful services.
Refreshing the page, on either network, reloads the page, but removes all styling and js files attached to that page. Going to another link does not effect the styling, except for the issue noted above.
Configurations
Nginx
VHost in sites-available, symlinked to sites-enabled.
upstream claxon {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name claxon;
root /var/www;
location ~* ^/claxon/ {
alias /var/www/claxon/public;
proxy_pass http://claxon;
}
location ^~ /assets/ {
root /var/www/claxon/public/claxon;
}
location ^~ /original_user_images/ {
root /var/www/claxon/public/claxon;
}
}
Rails App
config/initializers/mount_location.rb
if Rails.env.production?
Rails.application.config.relative_url_root = '/claxon'
end
config.ru
map Rails.application.config.relative_url_root || '/' do
run Rails.application
end
config/environments/production.rb
# Configures assets to be compiled under public/claxon/assets
config.assets.prefix = 'claxon/assets'
Additional Details
This app is being deployed to the server using capistrano, and the
current folder is being symlinked to the /var/www/claxon folder.
This app uses carrierwave for user image uploads.
The answer to this question was to ultimately configure the rails app to server the assets from a 'asset_host'. I set the asset host url to be the same as if connecting to the server from the enterprise network, as the developer network is contained within it, but the enterprise network cannot see the development network. Configuring it this way allows for both networks to receive the assets, and work across a refresh.
This final configuration in the production.rb file is as such.
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
config.action_controller.asset_host = "https://foo.bar.com/claxon/"
This allows all assets to be derived from https://foo.bar.com/claxon/claxon/assets/....

How to make unicorn run a Rails 3.0 app under a path?

I'm migrating from Passenger to Unicorn, and with Passenger I used to run my Rails 3.0 app with the RailsBaseURI option to prefix all URLs with '/blah' for example.
When running the same app under Unicorn, I pass '--path /blah' to unicorn_rails, but the server still serves things as http://server:3000/etc/etc, instead of http://server:3000/blah/etc/etc - I see some assets being requested via /blah/ (like JS files, and so on), but the various links still do not have '/blah/' before them.
So - to summarise - how to I get Unicorn to mount my app under /blah, so that all requests work with '/blah' prepended to the path and all links and assets are created with '/blah/' prepended to them?
Thanks
Here's what I've discovered:
To get a Rails app to serve asset and link URLs, you have to set an environment variable before it starts:
ENV['RAILS_RELATIVE_URL_ROOT'] = '/prefix'
Then, as #d11wtq said, to get the Rack-compatible server (in this case, Unicorn) to actually serve the app under a prefix, you have to, in your config.ru file, instead of the usual run line, do the following:
run Rack::URLMap.new(
ENV['RAILS_RELATIVE_URL_ROOT'] => Rails.application
)
I believe putting something like this in your config.ru should do it:
require ::File.expand_path('../config/environment', __FILE__)
run Rack::URLMap.new(
"/blah" => Rails.application
)
untested
The easy and reliable solution is to set the prefix in your front-end setup.
With passenger+nginx for example, you could use something like this:
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
passenger_enabled on;
passenger_base_uri /prefix;
}
Nothing to change in the source code, one line setup.
But you said you're using unicorn, which front-end are you using ?
Using nginx is should be possible with something like this:
location /prefix {
rewrite ^/prefix/(.*) /$1 break;
proxy_pass http://localhost:8000;
}

Apache2 Won't Reload: Looking for a File I Intentionally Deleted

Okay, so I'm following a guide to get set up with a Rails production server, and it says the following in the Apache2 setup:
We have to create a virtual host by creating a file in the "/etc/apache2/sites-available" directory (we will name it "site" - the file won't have any extension but it will be a text file).
$ sudo nano /etc/apache2/sites-available/site (this will create the file named "site" - can be any name - AND open it for editing)
Copy and paste this into that file (compare also with what the notes after installing mod_rails tells you):
VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot /home/user/public_html/site/public
/VirtualHost>
When I was first testing the waters with Apache I did as it said, making a fake scaffolded Rails app called "site". Now I want to use my real site, which we'll call "realthing." So I did
# sudo mv /etc/apache2/sites-available/site /etc/apache2/sites-available/realthing
And put my new settings into the renamed file. So far so good.
Then I went to restart Apache. Problems begin.
# sudo a2ensite realthing
Enabling site realthing.
To activate the new configuration, you need to run:
service apache2 reload
Okay, I can do that.
# sudo service apache2 reload
apache2: Syntax error on line 230 of /etc/apache2/apache2.conf: Could not open configuration file /etc/apache2/sites-enabled/site: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.
...fail!
Fail indeed. Nothing I can seem to do can get this thing to restart without flipping out about the missing "site" file. I check line 230 of /etch/apache2/apache2.conf for any specific references. Nope:
Include sites-enabled/
It's a generic reference to the folder containing "site". But no mention of "site".
So what's up? How do I get Apache to forget about the fake site "site" and move on to the real thing "realthing"? It's driving me insane that even a superuser reload is failing because Apache can't find a file that as far as I can tell it has no reason to expect to find.
Even a hard
sudo service apache2 stop
and
sudo service apache2 start
doesn't work. Again with the
* Starting web server apache2
apache2: Syntax error on line 230 of /etc/apache2/apache2.conf: Could not open configuration file /etc/apache2/sites-enabled/site: No such file or directory
Action 'start' failed.
This is driving me bonkers. Any ideas?
The Apache error log may have more information.
You probably still have a symlink from sites-enabled/site to the now missing sites-available/site

Is it a bad idea to put apache conf files in my rails app's config directory?

I have a dedicated CentOS server. I manage all my users, apps, and virtual hosts manually. I'm using Apache 2.2.3 and Passenger 3.0.7 to serve my apps. I have a typical httpd.conf file in /etc/httpd/conf/ that includes all *.conf files in my /etc/httpd/conf/vhosts/ directory. Normally for each app I create a new sample-domain.com.conf file in the vhosts directory.
However, I have a particular app that needs frequent apache configuration changes, and I'd like it to be more a part of my app and its version control. So I've moved my apache configuration file into the apps config directory. I added a script to my Capistrano deploy.rb that sets the permissions on the apache conf file in the app to 755. I added an include line in my vhosts that includes the symlinked current version of the apache conf file from the app.
Which brings me to my simple question: is this safe or a bad idea?
For frequent config changes in Apache, consider using a .htaccess file instead. Changing .conf files requires bouncing/hupping the server, and if a .conf file has an error, that'll kill the whole server and take down all sites. A .htaccess error will take down just the one site/directory where the file is.

Resources