Showing posts with label webserver. Show all posts
Showing posts with label webserver. Show all posts

Sunday, May 20, 2018

http configuration to connect different type of backened app server from single virtual host

Leave a Comment

I have a apache http server that acts as proxy to connect to backened app servers.

e.g. MachineA(https) -> MachineB(http:reverseproxy) -> MachineCn(http:App)

Here MachineA(Public_lb) port 9002 is mapped with MachineB(internal apache) port 7777.

In backened, I have different application servers running

for e.g.

  1. MachineC1 -> Weblogic
  2. MachineC2 -> Tomcat
  3. MachineC3 -> NodeJS
  4. MachineC4 -> Flask

Here there is single servername(MachineA: public_facing_lb) and port(9002). Here is my existing configuration in MachineB(apache reverseproxy server)looks like which works fine now for all weblogic connections. But when I add the proxy for other apps, it never works properly.

What I am doing wrong here ?

LoadModule weblogic_module   "/u01/oracle/ohssa/ohs/modules/mod_wl_ohs.so"  RewriteEngine On     RewriteCond %{HTTPS} on     RewriteRule ^$ http://%{HTTP_HOST} [L,R]        <IfModule mod_weblogic.c>        NameVirtualHost *:7777       <VirtualHost *:7777>         ServerName https://public_facing_lb:9002         RewriteEngine       On         RewriteOptions inherit         RewriteRule ^/$ /pod/reactaphome [PT]         Debug ALL         MatchExpression /         DebugConfigInfo ON         WLLogFile /var/log/httpd/wlproxy-qa.log         KeepAliveEnabled ON         KeepAliveSecs  15         WLProxySSLPassThrough ON         ProxyPreserveHost On        <Location /pod/reactapp1>        ProxyPass  http://nodejssrv1:1337        ProxyPassReverse  http://nodejssrv1:1337      </Location>       <Location /pod/flaskapp1>        ProxyPass  http://flasksrv1:8080        ProxyPassReverse  http://flasksrv1:8080      </Location>       <Location /pod/tomcatapp1>        ProxyPass  http://tomcatsrv1:8080        ProxyPassReverse  http://tomcatsrv1:8080      </Location>       <Location /pod/console>         SetHandler weblogic-handler         WebLogicHost wlssrv1         WeblogicPort 7001         WLSRequest On         ProxyPass  http://wlssrv1:7001/console         ProxyPassReverse http://wlssrv1:7001/console      </Location>         SetHandler weblogic-handler         WebLogicHost wlssrv1         WeblogicPort 7001         ProxyPass /pod/wlsapp1 http://wlssrv1:7001/wlsapp1         ProxyPassReverse /pod/wlsapp1 http://wlssrv1:7001/wlsapp1         ProxyPass /pod/wlsapp2 http://wlssrv1:7001/wlsapp2         ProxyPassReverse /pod/wlsapp2 http://wlssrv1:7001/wlsapp2         ProxyPass /pod/wlsapp3 http://wlssrv1:7001/wlsapp3         ProxyPassReverse /pod/wlsapp3 http://wlssrv1:7001/wlsapp3          ProxyPass /wlsapphome/global http://wlssrv1:7001/resources/getGlobalAppsList         ProxyPassReverse /wlsapphome/global http://wlssrv1:7001/resources/getGlobalAppsList         ProxyPass /wlsapphome http://wlssrv1:7001/resources/getAppsList         ProxyPassReverse /wlsapphome http://wlssrv1:7001/resources/getAppsList       </VirtualHost>     </IfModule>  

I might be doing mistake in putting the other app config inside the weblogic if module. If I am creating multiple virtual hosts, at any point of time only the first virtualhost works.

Do I need to load modules for tomcat, nodejs and flask to communicate, as the pages get loaded broken. Like mod_wl_ohs used for weblogic ?

1 Answers

Answers 1

I don't know why your ifmodule statement is applied to the whole VirtualHost, why not limit it to only to the rules for weblogic reverse proxy?

Also you didn't close your Location statements, checkout this modified file:

LoadModule weblogic_module   "/u01/oracle/ohssa/ohs/modules/mod_wl_ohs.so" RewriteEngine On RewriteCond %{HTTPS} on RewriteRule ^$ http://%{HTTP_HOST} [L,R]  <VirtualHost *:7777>     ServerName https://public_facing_lb:9002     RewriteEngine       On     RewriteOptions inherit     RewriteRule ^/$ /pod/reactaphome [PT]     Debug ALL     MatchExpression /     DebugConfigInfo ON     WLLogFile /var/log/httpd/wlproxy-qa.log     KeepAliveEnabled ON     KeepAliveSecs  15     WLProxySSLPassThrough ON     ProxyPreserveHost On     <Location /pod/reactaphome>      ProxyPass  http://admiring_agnesi:8080      ProxyPassReverse  http://admiring_agnesi:8080    </Location>     <Location /pod/tomcatapp>      ProxyPass  http://admiring_agnesi:1337      ProxyPassReverse  http://admiring_agnesi:1337    </Location>     <IfModule mod_weblogic.c>     <Location /pod/console>       SetHandler weblogic-handler       WebLogicHost wlssrv1       WeblogicPort 7001       WLSRequest On       ProxyPass  http://wlssrv1:7001/console       ProxyPassReverse http://wlssrv1:7001/console    </Location>      SetHandler weblogic-handler     WebLogicHost wlssrv1     WeblogicPort 7001     ProxyPass /pod/wlsapp1 http://wlssrv1:7001/wlsapp1     ProxyPassReverse /pod/wlsapp1 http://wlssrv1:7001/wlsapp1     ProxyPass /pod/wlsapp2 http://wlssrv1:7001/wlsapp2     ProxyPassReverse /pod/wlsapp2 http://wlssrv1:7001/wlsapp2     ProxyPass /pod/wlsapp3 http://wlssrv1:7001/wlsapp3     ProxyPassReverse /pod/wlsapp3 http://wlssrv1:7001/wlsapp3      ProxyPass /wlsapphome/global http://wlssrv1:7001/resources/getGlobalAppsList     ProxyPassReverse /wlsapphome/global http://wlssrv1:7001/resources/getGlobalAppsList     ProxyPass /wlsapphome http://wlssrv1:7001/resources/getAppsList     ProxyPassReverse /wlsapphome http://wlssrv1:7001/resources/getAppsList    </IfModule>   </VirtualHost> 

Could you try with that? All the requests to the *:7777 port will be handled.

Read More

Monday, July 31, 2017

How to set X-Frame Options to ALLOW-FROM https://example.com and SAMEORIGIN on server

Leave a Comment

I have a requirement to set the X-Frame options on the server level to either:

Understand that X-Frame Options are mutually exclusive. See here.

However, my application requires framing in https://example.com and also from its SAMEORIGIN.

Please advise if there is a way around this while retainining my application's requirement to having allow framing on the same origin and be framed on 1 external site.

Or is this impossible?

1 Answers

Answers 1

In addition to only supporting one instance of the header, X-Frame-Options does not support any more than just one site, SAMEORIGIN or not.

You'll have to use Content-Security-Policy and frame-ancestors, which does support multiple origins, like so:

Content-Security-Policy: frame-ancestors 'self' https://example.com 

A couple notes to bear in mind:

Read More

Tuesday, April 4, 2017

how to redirect a git-server address?

Leave a Comment

(suppose) I have my own git, so you can do

  git clone https://official.example.org/myproject.git 

But, at my server official.example.org I want to redirect it to Github. How to do it at UBUNTU 16LTS standard git-server? It is an usual web-server redirect (eg. Apache) or need special preparation?

PS: the technology exist, as announced here.

2 Answers

Answers 1

As far as I know, it's not possible. On Github, the old repository will be redirected to the new one in the same domain and it's the main point here.

Trying to redirect official.example.org to github.com will broke the certificate's chain, making it impossible to handle.

Answers 2

I use the git post-receive hook in my buildfarm to automatically build projects in Jenkins when code is pushed to my git repository. You could do something similar with some of the other git hooks on your server to push code to github.

Similarly, on github you could define a webhook to update your git repository on official.example.org whenever code in the github repository is updated. Something like this answer maybe.

Read More

Thursday, January 26, 2017

Decrypt OpenSSL binary through NGINX as it is received ( on the fly )

Leave a Comment

I have a small embedded Linux device that has 128 MB flash storage available to work with as a scratchpad. This device runs an NGINX web server. In order to do a firmware update - the system receives an encrypted binary file as an HTTPS POST through NGINX to the scratchpad. The system then decrypts the file and flashes a different QSPI flash device in order to complete the update.

The firmware binary is encrypted outside the device like this:

openssl smime -encrypt -binary -aes-256-cbc -in plainfile.zip -out encrypted.zip.enc -outform DER yourSslCertificate.pem 

The firmware binary is decrypted, after being received through NGINX, on the device like this:

openssl smime -decrypt -binary -in encrypted.zip.enc -inform DER -out decrypted.zip -inkey private.key -passin pass:your_password 

I'd really like to decrypt the binary as it is received ( on the fly ) through NGINX, so that it appears on the flash scratchpad in it's decrypted form.

I've been unable to find any existing NGINX modules on Google that would do this. How might I accomplish this? Thanks.

2 Answers

Answers 1

First of all, you need to understand one thing. While nginx will decrypt file - all other request will be blocked. That's why nginx does not support CGI, only FastCGI.

If it ok for you (for example, nginx used only for update purposes), you can use perl or lua extension: http://nginx.org/en/docs/http/ngx_http_perl_module.html, https://github.com/openresty/lua-nginx-module

Using this modules you can exec shell. For access uploaded file need to set client_body_in_file_only directive - https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_in_file_only

Example for perl module (untested):

location /upload {   client_body_in_file_only clean;   perl 'sub {     my $r = shift;     if ($r->request_body_file) {        system("openssl smime -decrypt -binary -in ".$r->request_body_file." -inform DER -out /tmp/decrypted.zip -inkey private.key -passin pass:your_password");     }   }'; } 

But much better to use fastcgi. You can use light fastcgi wraper for it, for example, fcgiwrap https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/

Answers 2

There's a widely-known attack against non-event-based servers like Apache known as Slowloris, where the client initiates a number of HTTP requests without sending them in full (where each request is instead being sent in part for a prolonged interval, which is a very cheap operation, both to send and receive, for an event-based architecture like that of nginx, but at the same time is very expensive for some other servers).

As a proxy server, nginx protects its backends from such an attack. Indeed, protection may come at a cost in certain circumstances, and can be turned off with the …_request_buffering directives:

What you would do is disable the request buffering, and then pipe the incoming file directly to openssl as it is received.

Note that you can always use /dev/fd/0 in place of the filename to specify stdin (depending on the tool, using - in place of the filename may also be an option).

Read More

Wednesday, April 27, 2016

Nginx as a web server or Node JS with Cloudfront CDN

Leave a Comment

I have read many articles that the main advantage of using Nginx as a web server is that it fastens you performance, especially because it works fast with a static data.

I already uses Cloudfront CDN (Amazon Services) for fastening the static data.

So, do I have any real reasons to prefer using Nginx over Node JS as a web server?

2 Answers

Answers 1

No advantage in your case. Choosing a CDN to deliver your static content was a great idea. (CDN's not only serve your content, but they cache it around their network so most locales see equivalent performance.) This offloads a significant amount of labor from your NodeJS application server.

However NGINX can be very useful in conjunction with an application server like NodeJS. Most people use NGINX as a reverse proxy, that is it sits in front of a cluster of application servers and distributes traffic load evenly.

Other cool tricks include hotswapping NGINX configuration for blue green deployments; so you never have to halt your service for an upgrade.

If you have the money and the time these are tricks well worth having up your sleeve.

Answers 2

It depends what do you believe "real reasons" are.

I believe the most important reason includes security issues - Nginx is a dedicated web server, whereas Node.js is a JavaScript runtime, therefore Nginx focuses on serving-related issues, whereas Nodejs builtin server is just an additional utility, thus not receiving that much attention. Another benefit of such deployment is configurability - for example, you can switch your node runtimes with virtually no downtime (since you can run two nodejs instances at the same time) or even slowly move the traffic to your new server.

You can also take a look at: Using Node.js only vs. using Node.js with Apache/Nginx and http://blog.modulus.io/supercharge-your-nodejs-applications-with-nginx

Perhaps you may be interested in a more general question as well, regarding application servers vs web servers: What is the difference between application server and web server?

Read More