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.
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 :
- nginx as reverse proxy
- fastcgi mono server as CGI server for existing mono apps
- Glassfish as Java server.
- Netbeans as IDE for Java server development.
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.
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.
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)
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.
NOTE: update on 20190924. ASPX will not be kept.
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.
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.
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!