Share this blog!

Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts
I have been using a VPS in which I have hosted a JSP project and after spending quite a long time on the internet, I found the correct way to install the SSL certificate I bought. It is always better to follow the instructions of your certificate provider, but sometimes, these instructions can be somewhat misleading, with popular assumptions such as owning a perfect machine or having an expert knowledge on the prerequisites. In this post, I will be trying to loosen up some such problems but feel free to comment any suggestions or remarks.


The scenario


I have Tomcat 8.5 running on my VPS with Apache server and in that, I have deployed a web app on the root (Let's say http://mysitesname.com/).

Creating the CSR


When you are purchasing an SSL certificate, you will be prompted to input a CSR code which can be easily generated using OpenSSL by running the following command on the command line:

openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr

This command will generate two files (server.key and server.csr. Never give away your private key ie server.key)

Once you upload the CSR code to the certificate provider, you will be asked to activate it. (Eg: you might need to place a certain file at the root of the site, respond with an admin email etc)

Once the SSL is activated, then only you can install it.

Installing the SSL


I purchased a Comodo SSL certificate and since I selected a PositiveSSL, I could download 3 files such as:
  • mysitesname_com.crt
  • mysitesname_com.p7b
  • mysitesname_com.ca-bundle
Let's say I downloaded those files on a folder names /home/ssl on the VPS and I copied the previously created CSR and Key files into the same folder for convenience.

Installing SSL on Apache vs Tomcat

I spent an annoyingly long time on trying to install SSL on tomcat and then realized that according to my requirement, where I had to install was on Apache. It's basically because that I had previously modified my Apache's virtualhosts file to direct to the deployed webapp. So even though the running webapp was deployed on Tomcat, the http was provided by Apache. It is because Apache is an HTTP Server, serving HTTP while Tomcat is a Servlet and JSP Server serving Java technologies. Tomcat is a servlet container. A servlet, at the end, is a Java class. JSP files (which are similar to PHP, and older ASP files) are generated into Java code (HttpServlet), which is then compiled to .class files by the server and executed by the Java virtual machine.

Once the certificate files are stored on the VPS, its only a matter of modifying Apache's virtualhosts. Since my VPS is Ubuntu, the file I must modify is /etc/apache2/sites-enabled/mysitesname.com.conf. The filename and the path may vary according to the OS installed.

The file already contained a virtual host on port 80. For this purpose a new host entry must be added on port 443 as follows:

Listen 443

<VirtualHost _default_:443>

        ServerName mysitesname.com

        SSLEngine on

        SSLCertificateFile "/home/ssl/mysitesname_com.crt"

        SSLCertificateKeyFile "/home/ssl/server.key"

        SSLCACertificateFile "/home/ssl/mysitesname_com.ca-bundle" 

</VirtualHost>

Since I had set my webapp to be hosted on the root, my previous settings too had to be added, after which the complete entry will look like the following:

Listen 443

<VirtualHost _default_:443>

        ServerName mysitesname.com

        SSLEngine on

        SSLCertificateFile "/home/ssl/mysitesname_com.crt"

        SSLCertificateKeyFile "/home/ssl/server.key"

        SSLCACertificateFile "/home/ssl/mysitesname_com.ca-bundle"

        ProxyPreserveHost On

        ProxyPass / http://mysitesname.com:8080/

        ProxyPassReverse / http://mysitesname.com:8080/

</VirtualHost>


Redirecting to HTTPS

In order to redirect your domain traffic to your https domain, add the following in your conf file.

Listen 443

<VirtualHost *:80>

        RewriteEngine On 

        RewriteCond %{HTTPS} off 

        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

</VirtualHost>

After the conf file is modified, restart the server using service apache2 restart.

If it generates an error saying Invalid command 'SSLEngine' , you will have to enable the ssl module from the commons package by running sudo a2enmod ssl and restart again.

That's it! Try browsing the site with https and ensure it is installed correctly.


This post presents a sample data service created by WSO2's Data Services Server and incorporates a MySQL database.

Installing WSO2 DSS

You can follow the instructions on this document to install the server.

The database

I will be using MySQL as the source of the data. Therefore your machine must have MySQL installed in it. 

Quick tip: 

How to install MySQL in Ubuntu: use following commands.

$ sudo apt-get update
$ sudo apt-get install mysql-server
$ sudo mysql_secure_installation

To set up JDBC Driver: 

$ sudo apt-get install libmysql-java

and add ":/usr/share/java/mysql-connector-java.jar" to the PATH in etc/environment. Check related links for more information.


Additionally, you need to copy the mysql-connector-java-5.XX-bin.jar file into the /repository/components/lib/ directory.

I have created the following simple table(named person) in the database peopledb, which will be used in this sample.


Create the data service

Start the Data Services Server (In Linux, run command ./wso2server.sh in server_home/bin)


In the Main tab, under Services →Data Service, click Create. Specify a name and click Next.


Add new data source

Specify a name for the data source and set the parameters to point to the MySQL database.
Save and click Next.

Create a query

Just like its name stands for, the queries retrieve/write data. The following settings define a query to get all the entries of the table. This section introduces another query and an operation that uses a different sql query


The output is set as xml and People and Person are set as group and row so as to get an output in the form of:
<people>
    <person>
        ....info
    </person>
</people>

To map the output of the query to the xml tags, an output mapping must be defined. Click on Add New Output Mapping and set the mappings as follows.


Save and click Next.

Add operation to query

An operation can bind a query to the server. Simply define a name to the operation and set the query.
Click Finish and you will be redirected to the services page with your new service up and running.

Deploy the service

The new service will be running if the defined settings were correct. Clicking on the service will open the statistics of it.


As the Endpoints, it will show the URL of the service we just created. To use the operation we defined (getPeople) simply go the URL:-
http://172.17.0.1:9763/services/PersonDataService/getPeople

Multiple queries and operations

The following is another query added to the same data service to get information on one entry. Add a new query as follows:
I have used JSON as the output format. And bind an operation to it as follows. 

Here is another query - an insert query to add Barry to the table.

Related links



How to view login information

Basically Ubuntu saves all the log information in a log file inside /var/log/auth.log which you can access manually or use the following command in the terminal.

sudo less /var/log/auth.log 


How to disable guest login


In the file /etc/lightdm/lightdm.conf add the following line

allow-guest=false

If you are using a newer version of Ubunutu, try the file /usr/share/lightdm/lightdm.conf.d.



Make sure to restart the system to take effect.

In order to allow guest login again, remove the code line from the file.
Previous PostOlder Posts Home