<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Víctor Orozco</title>
    <description>The latest articles on DEV Community by Víctor Orozco (@tuxtor).</description>
    <link>https://dev.to/tuxtor</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F213127%2F4558fa2b-349c-42a2-8612-5016db486148.jpg</url>
      <title>DEV Community: Víctor Orozco</title>
      <link>https://dev.to/tuxtor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tuxtor"/>
    <language>en</language>
    <item>
      <title>How to install Payara 5 with NGINX and Let's Encrypt over Oracle Linux 7.x</title>
      <dc:creator>Víctor Orozco</dc:creator>
      <pubDate>Thu, 02 May 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/tuxtor/how-to-install-payara-5-with-nginx-and-let-s-encrypt-over-oracle-linux-7-x-34ke</link>
      <guid>https://dev.to/tuxtor/how-to-install-payara-5-with-nginx-and-let-s-encrypt-over-oracle-linux-7-x-34ke</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--79-VJCAC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/payarassl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--79-VJCAC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/payarassl.png" alt="Payara SSL" title="Payara SSl"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From field experiences I must affirm that one of the greatest and stable combinations is Java Application Servers + Reverse Proxies, although some of the functionality is a clear overlap, I tend to put reverse proxies in front of application servers for the following reasons (&lt;a href="https://www.nginx.com/resources/glossary/reverse-proxy-server/"&gt;please see NGINX page for more details&lt;/a&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Load balancing:&lt;/strong&gt; The reverse proxy acts as traffic cop and could be used as API gateway for clustered instances/backing services&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Web acceleration:&lt;/strong&gt; Most of our applications nowadays use SPA frameworks, hence it is worth to cache all the js/css/html files and free the application server from this responsibility&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Most of the HTTP requests could be intercepted by the reverse proxy &lt;strong&gt;before&lt;/strong&gt; any attempt against the application server, increasing the opportunity to define rules&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSL Management:&lt;/strong&gt; It is easier to install/manage/deploy OpenSSL certificates in Apache/NGINX if compared to &lt;a href="https://en.wikipedia.org/wiki/Java_KeyStore"&gt;Java KeyStores&lt;/a&gt;. Besides this, &lt;a href="https://letsencrypt.org/"&gt;Let's Encrypt&lt;/a&gt; officially support NGINX with plugins.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;To demonstrate this functionality, this tutorial combines the following stack in a classic (non-docker) way, however most of the concepts could be useful for Docker deployments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Payara 5 as application server&lt;/li&gt;
&lt;li&gt;NGINX as reverse proxy&lt;/li&gt;
&lt;li&gt;Let's encrypt SSL certificates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is assumed that a clean Oracle Linux 7.x (7.6) box will be used during this tutorial and tests will be executed over Oracle Cloud with &lt;code&gt;root&lt;/code&gt; user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bAVX_qT6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/oraclelinux.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bAVX_qT6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/oraclelinux.png" alt="Oracle Linux" title="Oracle Linux"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparing the OS
&lt;/h2&gt;

&lt;p&gt;Since Oracle Linux is binary compatible with RHEL, &lt;a href="https://fedoraproject.org/wiki/EPEL"&gt;EPEL&lt;/a&gt; repository will be added to get access to Let's Encrypt. It is also useful to update the OS as a previous step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum -y update
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up Payara 5
&lt;/h2&gt;

&lt;p&gt;In order to install Payara application server a couple of dependencies will be needed, specially a Java Developer Kit. For instance OpenJDK is included at Oracle Linux repositories.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum -y install java-1.8.0-openjdk-headless
yum -y install wget
yum -y install unzip
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once all dependencies are installed, it is time to download, unzip and install Payara. It will be located at &lt;code&gt;/opt&lt;/code&gt; following standard Linux conventions for external packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /opt
wget -O payara-5.191.zip https://search.maven.org/remotecontent?filepath=fish/payara/distributions/payara/5.191/payara-5.191.zip
unzip payara-5.191.zip
rm payara-5.191.zip
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It is also useful to create a &lt;code&gt;payara&lt;/code&gt; user for administrative purposes, to administrate the domain(s) or to run Payara as Linux service with systemd:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adduser payara
chown -R payara:payara payara5
echo 'export PATH=$PATH:/opt/payara5/glassfish/bin' &amp;gt;&amp;gt; /home/payara/.bashrc
chown payara:payara /home/payara/.bashrc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;A systemd unit is also needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo '[Unit]
Description = Payara Server v5
After = syslog.target network.target

[Service]
User=payara
ExecStart = /usr/bin/java -jar /opt/payara5/glassfish/lib/client/appserver-cli.jar start-domain
ExecStop = /usr/bin/java -jar /opt/payara5/glassfish/lib/client/appserver-cli.jar stop-domain
ExecReload = /usr/bin/java -jar /opt/payara5/glassfish/lib/client/appserver-cli.jar restart-domain
Type = forking

[Install]
WantedBy = multi-user.target' &amp;gt; /etc/systemd/system/payara.service
systemctl enable payara
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Additionally if remote administration is needed, secure admin should be enabled:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo -u payara /opt/payara5/bin/asadmin --host localhost --port 4848 change-admin-password
systemctl start payara
sudo -u payara /opt/payara5/bin/asadmin --host localhost --port 4848 enable-secure-admin
systemctl restart payara
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZvFmUXaL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/payaraboot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZvFmUXaL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/payaraboot.png" alt="Payara Boot" title="Payara Boot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Oracle Cloud default configuration will create a VNIC attached to your instance, hence you should check the rules in order to allow access to ports.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wmmm7en4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/ingresrules.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wmmm7en4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/ingresrules.png" alt="Ingres Rules" title="Ingres Rules"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, Oracle Linux instances have a restricted set of rules in iptables and SELinux, hence ports should be opened with firewalld and SELinux should be configured to allow reverse proxy traffic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --zone=public --permanent --add-port=4848/tcp
setsebool -P httpd_can_network_connect 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With this, the access is guaranteed to http+https+payara admin port.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up NGINX reverse proxy
&lt;/h2&gt;

&lt;p&gt;NGINX is available at EPEL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum -y install nginx
systemctl enable nginx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;At this time your will need a FQDN pointing to your server, otherwhise Let's encrypt validation won't work. For this tutorial the &lt;code&gt;ocl.nabenik.com&lt;/code&gt; domain will be used. If your domain propagated properly you should see a page like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1Sya9kSu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/nginxproxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1Sya9kSu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/nginxproxy.png" alt="NGINX Proxy" title="NGINX Proxy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't worry the Fedora logo is due EPEL usage, but you're running Oracle Linux :).&lt;/p&gt;

&lt;p&gt;Now it's time to setup NGINX as reverse proxy, an opinionated deployment option is to create a &lt;code&gt;/etc/nginx/sites-available&lt;/code&gt; and &lt;code&gt;/etc/nginx/sites-enabled&lt;/code&gt; structure inside NGINX configuration, to isolate/manage multiple domains with the same instance (aka virtual hosts).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p /etc/nginx/sites-available
mkdir -p /etc/nginx/sites-enabled
mkdir -p /var/www/ocl.nabenik.com/
chown -R nginx:nginx /var/www/ocl.nabenik.com

echo 'server {
    server_name ocl.nabenik.com;

    gzip on;
    gzip_types text/css text/javascript text/plain application/xml;
    gzip_min_length 1000;

    location ^~ /.well-known/acme-challenge/ {
        allow all;
        root /var/www/ocl.nabenik.com/;
        default_type "text/plain";
        try_files $uri =404;
    }

    location / {
        proxy_pass http://localhost:8080;
        proxy_connect_timeout 300;
        proxy_send_timeout 300;
        proxy_read_timeout 300;
        send_timeout 300;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    listen 80;
}' &amp;gt; /etc/nginx/sites-available/ocl.nabenik.com.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To enable the new host, a symlink is created on &lt;code&gt;sites-enabled&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ln -s /etc/nginx/sites-available/ocl.nabenik.com.conf /etc/nginx/sites-enabled/ocl.nabenik.com.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After that you should include the following line inside &lt;code&gt;/etc/nginx/nginx.conf&lt;/code&gt;, just before config file ending.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;include /etc/nginx/sites-enabled/*.conf;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It is also useful to check your configuration with &lt;code&gt;nginx -t&lt;/code&gt;, if all works property you should reach payara after NGINX reload.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1PTQ15DQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/reversepayara.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1PTQ15DQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/reversepayara.png" alt="Reverse Payara" title="Reverse Payara"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Let's Encrypt
&lt;/h2&gt;

&lt;p&gt;Once the reverse proxy is working, certbot should be enough to add an SSL certificate, the plugin itself will create a challenge at &lt;code&gt;^~ /.well-known/acme-challenge/&lt;/code&gt;, hence the proxy exclusion is mandatory (as reflected in the previous configuration step).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install -y certbot-nginx
certbot --nginx -d ocl.nabenik.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;One of the caveats of using certbot is the dependency of python version. Another alternative if you find any issues is to install it with &lt;code&gt;pip&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install -y python-pip
pip install certbot-nginx
certbot --nginx -d ocl.nabenik.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If everything works as expected, you should see the Payara page under SSL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--79-VJCAC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/payarassl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--79-VJCAC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.vorozco.com/images/posts/reversepayara/payarassl.png" alt="Payara SSL" title="Payara SSL"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally and most importantly, Let's Encrypt certificates are valid just for 90 days, hence you could add certification renewal (&lt;code&gt;crontab -e&lt;/code&gt;) as a cron task&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;15 3 * * * /usr/bin/certbot renew --quiet
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>java</category>
    </item>
  </channel>
</rss>
