Deploy Grape API with Nginx/Passenger - ruby

I have Nginx and Passenger installed on my server. Trying to run a Grape (Rack) API off it.
When I deploy Rails applications I have this server block in Nginx conf;
server {
listen 80;
server_name yourserver.com;
# Tell Nginx and Passenger where your app's 'public' directory is
root /path-to-app/public;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /path-to-ruby;
}
The instructions on Passenger's tutorial are;
The server block's root must point to your application's public
subdirectory.
What would this root be in case of my Grape API?

In case of grape, you need to create an empty public folder and point to this folder in the sever block.

Related

Deploy springboot application and react application to ubuntu server

I created a simple application, which consists of a reactjs frontend and a spring boot app as backend. It works fine on my local environment; with the react app running on port 3000, and the spring app running on port 9000.
I am trying to host this application in the staging environment. I want to host both the reactjs and spring boot app on a ubuntu server that I have on digitalocean. I have managed to deploy the reactjs frontend using nginx and now I want to deploy the backend using apache2.
I am having difficulty deploying the Spring boot app. I have generated a WAR file.
In my react application I call the backend spring app to serve as the api to the frontend to the browser. I have set up apache app to listen on port 9000 see below:
<VirtualHost *:9000>
ServerName 46.101.34.160
ServerAdmin webmaster#localhost
DocumentRoot
/var/www/html/BackEndBookingAndCollections
</VirtualHost>
My configuration details for the frontend goes as follows in the file;
/etc/nginx/sites-available/FEBookingAndCollections
The contents is the following:
server {
listen 80;
root /var/www/FEBookingAndCollections/build;
listen [::]:80 default_server;
server_name 46.101.34.160;
index index.html index.htm;
location / {
try_files $uri /index.html;
}
location /api/bookings/ {
proxy_pass http://46.101.34.160:9000/api/bookings;
}
}
In google chrome's browser I get the following error:
Failed to load resource: net::ERR_CONNECTION_REFUSED :9000/api/bookings:1
With spring boot, you don't have to use external Tomcat. You can package your app to jar with embedded tomcat. You can find more info here - https://www.baeldung.com/deployable-fat-jar-spring-boot.
You can't deploy war file without a server. Just follow bellow steps
1) install tomcat
2) find tomcat webapps path ( /usr/local/tomcat/webapps )
3) copy your war file to webapps. ( use scp )
4) make sure your war file and tomcat listen on same port. 8080 or 9000
5) proxy your api though apache

404 running Mvc3 with Mono on Raspberry Pi with Nginx and FastCgi

After lots and lots of hours put into configuring, formatting, reformatting, googling and reading what seems like hundred tutorials I still havent been able to run a MVC3 application on Raspberry Pi.
When I try to access it it throws a 404 error regardless if I try to access it via http://network_ip or http://network_ip/Home/Index
(source: shrani.si)
It does the same whether accessed from Nginx or XSP4 server.
My configuration:
nginx
server {
listen 80; ## listen for ipv4; this line is default and implied
root /var/www;
# Make site accessible from http://localhost/
server_name localhost;
access_log /var/log/nginx/localhost.log;
location / {
root /var/www/;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_index Home/Index;
include /etc/nginx/fastcgi_params;
}
}
MVC3 app should be deployed correctly (deleted Entity Framework references, copied Mvc references).
Im running Mono 2.10.8.1
Thank you

passenger_base_uri not working on passenger 4.0.0rc4

We are running ruby 2.0.0-p0 with passenger 4.0.0rc (nginx/1.2.7) on ubuntu 12.04 server in production (rails 3.2.12). Just notice that the passenger_base_uri in our nginx.conf is not pointing to the base subdir. Instead it return nothing. Here is passenger_base_uri in nginx.conf:
server {
listen 80;
server_name 154.49.55.6;
root /ebs/www/;
passenger_enabled on;
rails_env production;
passenger_base_uri /nbhy;
#for rails >= 3.1, assets pipeline
location ~ ^/assets/ {
expires max;
add_header Cache-control public;
add_header ETag "";
break;
}
}
A symlink nbhy was created on the server under /ebs/www and point to /ebs/www/nbhyop/current/public. The /nbhy is the base uri for rails app.
Here is the nginx error log,
[ 2013-05-06 17:47:00.5469 718/7f5097fc0700 Pool2/Implementation.cpp:1098 ]: [App 838 stdout]
2013/05/06 17:47:26 [error] 735#0: *104 open() "/ebs/www/authentify/session" failed (2: No such file or directory), client: 6.5.5.94, server: 154.49.55.6, request: "POST /authentify/session HTTP/1.1", host: "154.49.55.6", referrer: "http://154.49.55.6/nbhy/signin"
The path above should be: /ebs/www/nbhy/authentify/session instead of /ebs/www/authentify/session.
The same config is working on passenger 3.x. How to fix this problem? Thanks for help
I believe you were using passenger_base_uri for the wrong purpose. By specifying passenger_base_uri, you are saying:
"I have another web app, living under /nbhy"
I see in the Nginx output that you were doing a POST /authentify/session. Since you are not accessing any URL under /nbhy, the passenger_base_uri option has no effect. If you POST /nbhy/authentify/session, then it'll have effect.
Perhaps you want to set the virtual host's root to /ebs/www/nbhyop/current/public?

Sinatra on Nginx configuration - what's wrong?

I followed this tutorial more or less... I installed the passenger gem, executed passenger-install-ginx-module, sucessfully installed nginx and inserted this into the config:
server {
listen 80;
server_name localhost;
root /home/admin/sintest/public; # <--- be sure to point to 'public'!
passenger_enabled on;
}
In /home/admin/sintest I have: an empty public folder,
the config.ru:
require 'sinatra'
set :env, :production
disable :run
require './app.rb' #the app itself
run Sinatra::Application
and a test sinatra app.rb:
require 'sinatra'
get '/' do
"hello world!"
end
Now when I run nginx and open up http://localhost what I get is: 403 Forbidden
What am I doing wrong? Have I missed something?
Make sure that the user nginx is running as (in most cases 'nobody' or 'www-data') has permission to read the contents of your home directory /home/admin.
Also you can look into the nginx logs and read exactly what the error was.
I had the same error until I added passenger_root and passenger_ruby directives in the http block.

Multiple rack apps on nginx + passenger, one as root, the other not...config help

So I've got two apps I want to run on a server. One app I would like to be the "default" app--that is, all URLs should be sent this app by default, except for a certain path, lets call it /foo:
http://mydomain.com/ -> app1
http://mydomain.com/apples -> app1
http://mydomain.com/foo -> app2
My two rack apps are installed like so:
/var
/www
/apps
/app1
app.rb
config.ru
/public
/app2
app.rb
config.ru
/public
app1 -> apps/app1/public
app2 -> apps/app2/public
(app1 and app2 are symlinks to their respective apps' public directories). This is the Passenger setup for sub URIs described here: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_rack_to_sub_uri
With the following config I've got /foo going to app2:
server {
listen 80;
server_name mydomain.com;
root /var/www;
passenger_enabled on;
passenger_base_uri /app1;
passenger_base_uri /app2;
location /foo {
rewrite ^.*$ /app2 last;
}
}
Now, how do I get app1 to pick up everything else? I've tried the following (placed after the location /foo directive), but I get a 500 with an infinite internal redirect:
location / {
rewrite ^(.*)$ /app1$1 last;
}
I hoped that the last directive would prevent that infinite redirect, but I guess not. My /foo rewrite still works. And I can still go to http://mydomain.com/app1.
Any ideas? Thanks!
One way is to create a new config.ru file that dispatches the request to the correct app.
# /var/www/apps/config.ru
require './app1/app1'
require './app2/app2'
map ('/') { run App1 }
map ('/foo') { run App2 }
Of course, this means your apps have to be made in a way that they can live on the same execution space.

Resources