How to distribute microservices through nginx? - rest

I am new to microservices architecture and I have three REST services which was in a monothlithic architecture which I converted into three micro services (seperate DB and stuff) which have their own embedded web server (Spring boot fat jar) . Initially I had to serve the API through a reverse proxy so I map all the path (doamin:8080/application01) to something like this.
location /application01 {
proxy_pass http://username.github.io/project;
proxy_redirect http://username.github.io http://a.b;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
}
But now I had to it three times since all my microservices are having three different ports.I am reading about API gateway.But if I implement that wouldn't it be a single point failure.If then what is the diffence between a monothlithic and which i am implementing right now.Any help is appreciated.

Related

How to enable CORS in a self-hosted maptiler-server?

I want to configure Access-Control-Allow-Origin of a server machine running maptiler-server
but cannot find any documentation how to do it. I also want to know if there is any way to provide the maptiler-serve with access tokens generated by another web server to implement some sort of access control. I don't want the map server to be accessible by everyone. I want to restrict it to the users of a particular web application.
I found the solution on maptiler's page. Basicly I had to install a reverse proxy that did redirect to the maptiler-server. The example on their page uses Nginx as reverse-proxy server. To configure it in order to add Access-Control-Allow-Origin header on each responses, I had to extend the example with two more lines. So my location block inside configuration file looks like this:
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_pass http://127.0.0.1:3650;
proxy_hide_header 'Access-Control-Allow-Origin';
add_header 'Access-Control-Allow-Origin' '*' always;
}
The default configuration is located here /etc/nginx/sites-available/ or here /etc/nginx/conf.d/

Nginx reverse proxy for drools business central workbench

Issue in nginx reverse proxy for drools business central workbench. It is working fine till login page but after login it just shows loading gif which says please wait loding application.
THis is an issue with websocket, errai (the technology used by Drools) and nginx.
This configuration usually solves for me:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
Source: https://groups.google.com/g/drools-setup/c/86XzRYrvRcY

Logged into database 'yadi', but dbfilter rejects it; logging session out

Good morning,
I'm working on odoo 8, I created a new database 'yadi' but nothing happens, I always get database manager web page, and this is error on open-server.log:
Logged into database 'yadi', but dbfilter rejects it; logging session out.
Thank you for your help.
I am ODOO expert, It seems issue with nginx or apache2 configuration.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Host $host;
This header required in all proxy location. only / for this location not enough. All location with proxy_pass entry you need to add.
Even do for /web/static/ or website/static/ etc...
As ODOO multi host configured with dbfileter ^%h$, indicate all database based on host, so right header to forward.
In case you test without dbfilter, all works well but with dbfilter this may arise an issue.
Now follow my instruction, sure it will resolve ODOO bugs concerns.
You need to remove db-filter from openerp-server.conf
For search mention, you need to use following command.
locate openerp-server.conf
Go to path and remove db-filter parameter.
Generally, that file located under /etc/ folder.
Afterwards, reboot your system.

How to serve static files (images etc.) for a PSGI / Plack web app (in Perl)?

How to serve static files (images, javascript, stylesheets) for a PSGI / Plack based web app?
The answer would probably depend on what web server one uses, be it CGI, FastCGI, mod_psgi, or pure-Perl like Starman. I have heard that using Plack::Middleware::Static or Plack::App::File (together with Plack::App::URLMap) is to be used only for development...
As far as live deployment goes, a very uncomplicated (and fast) setup is if you let the web server deal with the static content and let the Plack app deal with the dynamic content. That would generally require at least 2 proxies in your web server config. Proxy A to your static files (assuming they're all generally in the same place) and proxy B to the port which your Plack app is deployed on.
For example, part of an nginx config might look like the following. Assume that the Plack app is running on port 5001 locally and that your static files are available under the url http://mydomainname.com/static
server {
listen 80;
server_name mydomainname.com;
location / {
proxy_pass http://localhost:5001/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Host $host;
}
location /static {
root /path/to/static/files;
}
}

Deploying two different Play! applications on the same hostname

I have developed 2 applications with Play Framework, accessing different information, so it does not make sense to merge then as a single app.
Now I need to deploy both apps on the same hostname, each one in a separate sub-folder (URI), for example:
example.com/payment/
example.com/cms/
And I am having problems with routes. I configured a nginx webserver to work as reverse proxy. It deliveries first page as expected.
But once I click anything, instead of going to /cms/Application/index it links back to /Application/index (without /cms/).
IMHO I believe I need change my routes file, hardcoding /cms/ on all paths, but it seems a bad approach because if I need to deploy the APP on another URI I will need to change routes again.
What is the best way to deploy two apps on the same hostname?
----- nginx.conf -----
...
...
...
location /cms {
proxy_pass http://localhost:9001/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /payment {
proxy_pass http://localhost:9002/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
...
...
...
----- nginx.conf -----
If you take a look at this thread on the Google Groups, you will see that the preferred approach is to the the context path.
The recommendation is to use a bootstrap job to set the context per application in the following way
Play.ctxPath="/project1";
Router.detectChanges(Play.ctxPath);
So your code would be
Play.ctxPath="/cms";
Router.detectChanges(Play.ctxPath);
etc.