Setting up a web server, just a little tougher…

Hello all!

As told in previous posts, I had decided to use Java as my main language, at least in a personal way. I started then to design & setup all environment about. This post it’s just a fast description how it’s configured the system, and steps followed up.

First of all, fixing the working way, the architecture of all. After some considerations, decided to :

  • Main /expensive duties will be realized by server, in Java.
  • Results of processes will be delivered to client/browser by REST/JSON services. This services will be developed in Java as well.
  • Any kind of dynamics, where continuous communication with server can produce lag or similar, will be developed in customer, presumably in Javascript.

This is not a very original architecture, I know. If It is not full MVVM, it’s derived or an attempt to resemble it: View will be in pure client JS/HTML; Model can be understood as Java core, and VM part can be understood as well as data-entity manipulations/adjustment before sending to client, or receiving from it, and the JSON communication itself. I preferred it for performance: pages will be pure HTML/Javascript, no JSP, no applets, etc; Core will be in Java supporting all consuming-processor tasks; communications between both will be the less fat possible, by REST/JSON service, taking care about message’s length. Surely in a future I’ll play a little with Angular JS, and another frameworks like it, that work same way, so this configuration it’s perfect nowadays for that, with each part very well differentiate and with a clear responsible (not code-behind or similar which I found that distorts initial wanted architecture).

I wanted as well, some more particular details :

  • To avoid Java dependency problems, will use Maven repositories for all kind of Java projects, and will try to use just the most extended .jars.
  • Existing .ASPX pages should be maintained as well. Perhaps removed in the future, but not now.
  • Should be prepared for another kind of communications instead of HTTP protocol. TCP/IP, and perhaps going down to analyze TCP/IP protocol deeper.

 

So, with this premises, I opted then for this configuration :

Go on, then. As my experience with nginx & Glassfish was (and it’s nowadays really) very poor, I checked up several tutorials about. So, there’s no sense here to repeat the same instructions, just reference to the main ones.

Setting up NGINX

nginx is an open source reverse proxy with a proven stability & performance, with a lot of features that can be used perfectly for a production environment. In fact, I recommended it at my job to my Systems/IT colleague, instead of our current  direct Apache & modsecurity configuration (that gave us some really ‘funny’ problems, surely by miss-configuration, as example block all petitions, or raising processor consumption up to sky and beyond, etc… ) & hardware balancer (that we don’t got real control but our datacenter, and sometimes we don’t know really what are they realizing with it). As everyday I learn something new, there’s a really big bunch of features to explore & use.

In my personal server, just follow this and others tutorials found, for a clean install & config.

Nginx.jpg

Setting up Glassfish

Glassfish is one of the main Java servers used around the world. Here there’s no special reason for me for choose it instead of JBoss, Apache or another Java servers.

snapshot3.png

I installed it and opened main domain (domain1) using its web console, to listening to a concrete port. As the idea was to be only accessible from inside, not accepting incoming petitions from exterior of VPS,  used then iptables to block that port in eth0 from incoming petitions. Found, by the way, a nice script to reset all rules.

As well, as this server will serve REST/JSON petitions, I added to nginx configuration the needed CORS headers, as one of nginx features it’s the possibility of rewriting responses. In fact, had found that just using add_header Accept-Control-Allow-Origin $http_origin; at response was enough for Chrome & Iceweasel)

As I’m used to recursive functions, and my VPS server it’s just for that, I maximize stack size with option -Xss129m at Glassfish’s JVM, using it’s web console

Maintaining existing .ASPX code. Fastcgi mono server.

As I’m yet interested in maintaining my .ASPX pages (http://vps264757.ovh.net/Default.aspx) I used the standard way to proxy petitions from nginx to fastcgi, as explained here and here and some other tutorials.

Develop server. Netbeans + Brackets

This now it’s very personal of course: I’m used to Eclipse, current Neon version, but found this bug when trying to deploy REST services, and knowing that meta-IDE Eclipse can be very powerful but with this kind of handicaps sometimes, I check that with Netbeans all work properly, so prepare it for this kind of projects.

snapshot1

As well, Brackets, that is an easy and light HTML/JS editor that got the very nice feature that no need to reload page in browser at every code change: it reloads automatically and show in realtimes your changes.

snapshot2.png

Got it all!

So, we got a Java server, Glassfish, and a CGI/.EXE/.ASPX server, Fastcgi, running & accesible just from inside same server, with CORS enabled for web service petitions.

So, let’s do something with this infrastructure!

Hope enjoyed!

Best,

 

 

 

 

 

Advertisements

One thought on “Setting up a web server, just a little tougher…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s