LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-15-2017, 11:28 AM   #1
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Rep: Reputation: Disabled
Properly configure Apache and TomEE for Https GWT application.


Hi,

I would like to learn how to properly configure Apache2 and Tomcat (TomEE)/8.5.6 (7.0.2) for GWT https application on fresh installation of Ubuntu Server 16.04.03.

Here are the steps that I used.

1. Configured my DNS records.

2. Configured "000-default-le-ssl.conf".

$ sudo nano /etc/apache2/sites-enabled/000-default-le-ssl.conf

Code:
<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName  zethanath.tk
        
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index//
        ProxyPassReverse / http://192.168.1.70:8080/Index//

        #DocumentRoot /var/www/html

        JKMount /* ajp13_worker

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost> 
    <VirtualHost *:443>
        ServerName www.zethanath.tk
        
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index//
        ProxyPassReverse / http://192.168.1.70:8080/Index//

        #DocumentRoot /var/www/html

        JKMount /* ajp13_worker

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>
    <VirtualHost *:443>
        ServerName  servlet.zethanath.tk
        
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index//
        ProxyPassReverse / http://192.168.1.70:8080/Index//

        #DocumentRoot /var/www/html

        JKMount /* ajp13_worker

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>
    </IfModule>
3. Configured "default-ssl.conf".

$ sudo nano /etc/apache2/sites-enabled/default-ssl.conf

Code:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
        ServerAdmin erick9.hi5@gmail.com
        ServerName  zethanath.tk
        
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index//
        ProxyPassReverse / http://192.168.1.70:8080/Index//

        #DocumentRoot /var/www/html
        JKMount /* ajp13_worker

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLEngine on

        SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                        SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                        SSLOptions +StdEnvVars
        </Directory>
</VirtualHost>

<VirtualHost _default_:443>
        ServerAdmin erick9.hi5@gmail.com
        ServerName  www.zethanath.tk
        
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index//
        ProxyPassReverse / http://192.168.1.70:8080/Index//

        #DocumentRoot /var/www/html
        JKMount /* ajp13_worker

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLEngine on

        SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                        SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                        SSLOptions +StdEnvVars
        </Directory>
</VirtualHost>
<VirtualHost _default_:443>
        ServerAdmin erick9.hi5@gmail.com
        ServerName  servlet.zethanath.tk
        
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index//
        ProxyPassReverse / http://192.168.1.70:8080/Index//

        #DocumentRoot /var/www/html
        JKMount /* ajp13_worker

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLEngine on

        SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                        SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                        SSLOptions +StdEnvVars
        </Directory>
    </VirtualHost>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
4. Configured "000-default.conf".

$ sudo nano /etc/apache2/sites-enabled/000-default.conf

Code:
<VirtualHost *:80 >
        ServerName  zethanath.tk
        
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index//
        ProxyPassReverse / http://192.168.1.70:8080/Index//

        #ServerAdmin erick9.hi5@gmail.com
        #DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        JKMount /* ajp13_worker

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =zethanath.tk
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

    </VirtualHost>

    <VirtualHost *:80 >
        ServerName  www.zethanath.tk
        ServerAlias zethanath.tk

        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index//
        ProxyPassReverse / http://192.168.1.70:8080/Index//

        #ServerAdmin erick9.hi5@gmail.com
        #DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        JKMount /* ajp13_worker

        RewriteEngine on
        RewriteCond %{SERVER_NAME} =www.zethanath.tk
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

    </VirtualHost>

    <VirtualHost *:80 >
        ServerName  servlet.zethanath.tk
        
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index//
        ProxyPassReverse / http://192.168.1.70:8080/Index//

        #ServerAdmin erick9.hi5@gmail.com
        #DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        JKMount /* ajp13_worker

        RewriteEngine on
        RewriteCond %{SERVER_NAME} =servlet.zethanath.tk
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

    </VirtualHost>

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
5. Checked these configuration syntax.

$ sudo apache2ctl configtest
Syntax OK

6. Restarted my server.

$ sudo systemctl restart apache2

7. Configured /etc/hosts.

$ sudo nano /etc/hosts

Code:
127.0.0.1 localhost
127.0.1.1 erick-ASRock-N68C-GS4-FX
192.168.1.70 www.zethanath.tk servlet.zethanath.tk zethanath.tk

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
8. Now, when I typed http://zethanath.tk, I would receive the following.

http://zethanath.tk, which is not what I wanted.

9. Now, when I typed http://www.zethanath.tk, I would receive (https) site, which is what I want.

10. Now, when I typed http://servlet.zethanath.tk, I would also receive (https) site, which is what I want as well.

My questions to you are.

1. What do I have to do to get the (https), when I typed http://zethanath.tk in the browser?
2. From question 1, if it is uncommon to serve http://zethanath.tk as the URL, what I should do to hide it?
3. What is the proper way to serve (http/https)://servlet.zethanath.tk behind my router only? If I understood correctly, servlet.zethanath.tk should be used as a reference from within Apache server to make redirection to TomEE server only correct? In other words, people outside my router should not be able to access directly correct?

For example, the final configuration from within Apache server should be something like this right?

ProxyPreserveHost On
ProxyPass / http://servlet.zethanath.tk:8080/NameofApp//
ProxyPassReverse / http://servlet.zethanath.tk:8080/NameofApp//

Thank you.
 
Old 08-16-2017, 03:28 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
1. What do I have to do to get the (https), when I typed http://zethanath.tk in the browser?
Use one vhost for all the http vhsots containing just a Redirect, like:
Code:
<VirtualHost *:80 >
  ServerName  www.zethanath.tk
  ServerAlias zethanath.tk servlet.zethanath.tk
    Redirect permanent / https://www.zethanath.tk/
</VirtualHost>

Quote:
2. From question 1, if it is uncommon to serve http://zethanath.tk as the URL, what I should do to hide it?
See if the configuration above does what you want.


Quote:
3. What is the proper way to serve (http/https)://servlet.zethanath.tk behind my router only? If I understood correctly, servlet.zethanath.tk should be used as a reference from within Apache server to make redirection to TomEE server only correct? In other words, people outside my router should not be able to access directly correct?

For example, the final configuration from within Apache server should be something like this right?

ProxyPreserveHost On
ProxyPass / http://servlet.zethanath.tk:8080/NameofApp//
ProxyPassReverse / http://servlet.zethanath.tk:8080/NameofApp//
Doh, I don't get what you mean, but you just need to use either one of mod_jk or a reverse proxy for tomcat. Besides mod_jk config is incomplete.
I also don't get, why you use both /etc/apache2/sites-enabled/000-default-le-ssl.conf and /etc/apache2/sites-enabled/default-ssl.conf. Aren't they the same?
Also since all 3 SSL vhosts are actually doing the same thing, you can use the same ServerAlias as in the http vhosts, to have only one SSL vhost.
And you don't need the 2nd trailing slash at the reverse proxy configuration.
So something like that should work:
Code:
    <VirtualHost *:443>
        ServerName www.zethanath.tk
        ServerAlias zethanath.tk servlet.zethanath.tk
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index/
        ProxyPassReverse / http://192.168.1.70:8080/Index/

        #DocumentRoot /var/www/html

        #JKMount /* ajp13_worker

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>
 
Old 08-16-2017, 02:17 PM   #3
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Hi there,

Quote:
1. What do I have to do to get the (https), when I typed http://zethanath.tk in the browser?
This morning, when I woke up, this issue disappeared mysteriously. I am able to get (https), when I type http://zethanath.tk now.

Quote:
I also don't get, why you use both /etc/apache2/sites-enabled/000-default-le-ssl.conf and /etc/apache2/sites-enabled/default-ssl.conf. Aren't they the same?
I am unsure why as well . However, I am guessing that, upon securing Apache with Let's Encrypt (sudo certbot --apache -d zethanath.tk -d www.zethanath.tk -d servlet.zethanath.tk), I ended up with both /etc/apache2/sites-enabled/000-default-le-ssl.conf and /etc/apache2/sites-enabled/default-ssl.conf.

I will try to hide my http:zethanath.tk by using what you suggested now.

1. sudo nano /etc/apache2/sites-enabled/000-default.conf

Code:
<VirtualHost *:80 >
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerName  www.zethanath.tk
        ServerAlias servlet.zethanath.tk zethanath.tk

        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index/
        ProxyPassReverse / http://192.168.1.70:8080/Index/

        #ServerAdmin erick9.hi5@gmail.com
        #DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        JKMount /* ajp13_worker

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        JKMount /* ajp13_worker

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.zethanath.tk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
2. sudo nano /etc/apache2/sites-enabled/000-default-le-ssl.conf

Code:
<IfModule mod_ssl.c>
<VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerName  www.zethanath.tk
        ServerAlias servlet.zethanath.tk zethanath.tk

        ProxyPreserveHost On
        ProxyPass / http://192.168.1.70:8080/Index/
        ProxyPassReverse / http://192.168.1.70:8080/Index/

        #DocumentRoot /var/www/html

        JKMount /* ajp13_worker

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

        SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

</VirtualHost>

</IfModule>
3. sudo nano /etc/apache2/sites-available/default-ssl.conf

Code:
<IfModule mod_ssl.c>
                <VirtualHost _default_:443>
                ServerAdmin erick9.hi5@gmail.com
                ServerName  www.zethanath.tk
                ServerAlias servlet.zethanath.tk zethanath.tk

                ProxyPreserveHost On
                ProxyPass / http://192.168.1.70:8080/Index/
                ProxyPassReverse / http://192.168.1.70:8080/Index/

                #DocumentRoot /var/www/html
                JKMount /* ajp13_worker

                # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
                # error, crit, alert, emerg.
                # It is also possible to configure the loglevel for particular
                # modules, e.g.
                #LogLevel info ssl:warn

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                # For most configuration files from conf-available/, which are
                # enabled or disabled at a global level, it is possible to
                # include a line for only one particular virtual host. For example the
                # following line enables the CGI configuration for this host only
                # after it has been globally disabled with "a2disconf".
                #Include conf-available/serve-cgi-bin.conf

                #   SSL Engine Switch:
                #   Enable/Disable SSL for this virtual host.
                SSLEngine on

                #   A self-signed (snakeoil) certificate can be created by installing
                #   the ssl-cert package. See
                #   /usr/share/doc/apache2/README.Debian.gz for more info.
                #   If both key and certificate are stored in the same file, only the
                #   SSLCertificateFile directive is needed.
                SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
                SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
                Include /etc/letsencrypt/options-ssl-apache.conf

                #   Server Certificate Chain:
                #   Point SSLCertificateChainFile at a file containing the
                #   concatenation of PEM encoded CA certificates which form the
                #   certificate chain for the server certificate. Alternatively
                #   the referenced file can be the same as SSLCertificateFile
                #   when the CA certificates are directly appended to the server
                #   certificate for convinience.
                #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

                #   Certificate Authority (CA):
                #   Set the CA certificate verification path where to find CA
                #   certificates for client authentication or alternatively one
                #   huge file containing all of them (file must be PEM encoded)
                #   Note: Inside SSLCACertificatePath you need hash symlinks
                #                to point to the certificate files. Use the provided
                #                Makefile to update the hash symlinks after changes.
                #SSLCACertificatePath /etc/ssl/certs/
                #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt

                #   Certificate Revocation Lists (CRL):
                #   Set the CA revocation path where to find CA CRLs for client
                #   authentication or alternatively one huge file containing all
                #   of them (file must be PEM encoded)
                #   Note: Inside SSLCARevocationPath you need hash symlinks
                #                to point to the certificate files. Use the provided
                #                Makefile to update the hash symlinks after changes.
                #SSLCARevocationPath /etc/apache2/ssl.crl/
                #SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl

                #   Client Authentication (Type):
                #   Client certificate verification type and depth.  Types are
                #   none, optional, require and optional_no_ca.  Depth is a
                #   number which specifies how deeply to verify the certificate
                #   issuer chain before deciding the certificate is not valid.
                #SSLVerifyClient require
                #SSLVerifyDepth  10

                #   SSL Engine Options:
                #   Set various options for the SSL engine.
                #   o FakeBasicAuth:
                #        Translate the client X.509 into a Basic Authorisation.  This means that
                #        the standard Auth/DBMAuth methods can be used for access control.  The
                #        user name is the `one line' version of the client's X.509 certificate.
                #        Note that no password is obtained from the user. Every entry in the user
                #        file needs this password: `xxj31ZMTZzkVA'.
                #   o ExportCertData:
                #        This exports two additional environment variables: SSL_CLIENT_CERT and
                #        SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
                #        server (always existing) and the client (only existing when client
                #        authentication is used). This can be used to import the certificates
                #        into CGI scripts.
                #   o StdEnvVars:
                #        This exports the standard SSL/TLS related `SSL_*' environment variables.
                #        Per default this exportation is switched off for performance reasons,
                #        because the extraction step is an expensive operation and is usually
                #        useless for serving static content. So one usually enables the
                #        exportation for CGI and SSI requests only.
                #   o OptRenegotiate:
                #        This enables optimized SSL connection renegotiation handling when SSL
                #        directives are used in per-directory context.
                #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>

                #   SSL Protocol Adjustments:
                #   The safe and default but still SSL/TLS standard compliant shutdown
                #   approach is that mod_ssl sends the close notify alert but doesn't wait for
                #   the close notify alert from client. When you need a different shutdown
                #   approach you can use one of the following variables:
                #   o ssl-unclean-shutdown:
                #        This forces an unclean shutdown when the connection is closed, i.e. no
                #        SSL close notify alert is send or allowed to received.  This violates
                #        the SSL/TLS standard but is needed for some brain-dead browsers. Use
                #        this when you receive I/O errors because of the standard approach where
                #        mod_ssl sends the close notify alert.
                #   o ssl-accurate-shutdown:
                #        This forces an accurate shutdown when the connection is closed, i.e. a
                #        SSL close notify alert is send and mod_ssl waits for the close notify
                #        alert of the client. This is 100% SSL/TLS standard compliant, but in
                #        practice often causes hanging connections with brain-dead browsers. Use
                #        this only for browsers where you know that their SSL implementation
                #        works correctly.
                #   Notice: Most problems of broken clients are also related to the HTTP
                #   keep-alive facility, so you usually additionally want to disable
                #   keep-alive for those clients, too. Use variable "nokeepalive" for this.
                #   Similarly, one has to force some clients to use HTTP/1.0 to workaround
                #   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
                #   "force-response-1.0" for this.
                # BrowserMatch "MSIE [2-6]" \
                #               nokeepalive ssl-unclean-shutdown \
                #               downgrade-1.0 force-response-1.0

        </VirtualHost>

</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
4. sudo apache2ctl configtest
Syntax OK

5. $ sudo systemctl restart apache2

6. $ sudo apache2ctl -S

Code:
VirtualHost configuration:
*:80                   www.zethanath.tk (/etc/apache2/sites-enabled/000-default.conf:1)
*:443                  is a NameVirtualHost
         default server www.zethanath.tk (/etc/apache2/sites-enabled/000-default-le-ssl.conf:2)
         port 443 namevhost www.zethanath.tk (/etc/apache2/sites-enabled/000-default-le-ssl.conf:2)
                 alias servlet.zethanath.tk
                 alias zethanath.tk
         port 443 namevhost www.zethanath.tk (/etc/apache2/sites-enabled/default-ssl.conf:2)
                 alias servlet.zethanath.tk
                 alias zethanath.tk
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex watchdog-callback: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
Now, when I type http://zethanath.tk, I still get https://zethanath.tk
When I type http://www.zethanath.tk, I also get https://www.zethanath.tk
When I type http://servlet.zethanath.tk, I get https://servlet.zethanath.tk as well.

Do I need to adjust anything from /etc/hosts, in order to hide zethanath.tk?

Code:
127.0.0.1       localhost
127.0.1.1       erick-ASRock-N68C-GS4-FX
192.168.1.70    www.zethanath.tk servlet.zethanath.tk zethanath.tk

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
I also wonder what people outside my router would see.
 
Old 08-17-2017, 12:35 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
I will try to hide my http:zethanath.tk by using what you suggested now.

1. sudo nano /etc/apache2/sites-enabled/000-default.conf
If you want to use just the SSL vhosts, you need just the "Redirect ..." in the http vhost definition, as I've told you in my previous post.


Quote:
Now, when I type http://zethanath.tk, I still get https://zethanath.tk
When I type http://www.zethanath.tk, I also get https://www.zethanath.tk
When I type http://servlet.zethanath.tk, I get https://servlet.zethanath.tk as well.

Do I need to adjust anything from /etc/hosts, in order to hide zethanath.tk?
What you mean by "hide zethanath.tk"? If you want to rewrite zethanath.tk to www.zethanath.tk, you can use mod_rewrite.


Quote:
I also wonder what people outside my router would see.
Nothing from here!

Last edited by bathory; 08-17-2017 at 12:48 AM. Reason: typos
 
Old 08-17-2017, 12:33 PM   #5
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Hi there,

Code:
If you want to use just the SSL vhosts, you need just the "Redirect ..." in the http vhost definition, as I've told you in my previous post.
I forgot to make adjustment, to the area below, for all the three files /etc/apache2/sites-enabled/000-default.conf, /etc/apache2/sites-enabled/000-default-le-ssl.conf, and /etc/apache2/sites-enabled/000-default.conf yesterday. I will do it right now. I could not see it clearly somehow yesterday. I need to use this format, so that I will not get syntax error, however.

Redirect permanent "/" "https://www.zethanath.tk/"

1. Made adjustment below to all the three files.

Before:
Code:
ProxyPreserveHost On
ProxyPass / http://192.168.1.70:8080/Index/
ProxyPassReverse / http://192.168.1.70:8080/Index/

JKMount /* ajp13_worker
After:
Code:
Redirect permanent "/" "https://www.zethanath.tk/"

#ProxyPreserveHost On
#ProxyPass / http://192.168.1.70:8080/Index/
#ProxyPassReverse / http://192.168.1.70:8080/Index/

#JKMount /* ajp13_worker
2. $ sudo apache2ctl configtest
Syntax OK

3. $ sudo systemctl restart apache2

4. I had to clear browser's cache, in order to get the results below.
- When I typed http://zethanath.tk, I got "Unable to connect".
- When I typed http://www.zethanath.tk, I got "https://www.zethanath.tk/ The page isn’t redirecting properly".
- When I typed http://servlet.zethanath.tk, I also got "https://www.zethanath.tk/ The page isn't redirecting properly".

For all three cases above, I think they are correct, because I do not have any welcome page in Tomcat, except a GWT application of mine.

Do you happen to know how to serve a GWT application (Google Web tool kit) as a welcome page? I name my GWT application as "Index" and its URL is

http://192.168.1.70:8080/Index/
 
Old 08-17-2017, 12:53 PM   #6
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
For all three cases above, I think they are correct, because I do not have any welcome page in Tomcat, except a GWT application of mine.

Do you happen to know how to serve a GWT application (Google Web tool kit) as a welcome page? I name my GWT application as "Index" and its URL is

http://192.168.1.70:8080/Index/
Okay. I have just made further adjustment.

After:
Code:
Redirect permanent "/" "https://www.zethanath.tk/"

ProxyPreserveHost On
ProxyPass / http://192.168.1.70:8080/Index/
ProxyPassReverse / http://192.168.1.70:8080/Index/

#JKMount /* ajp13_worker
2. $ sudo apache2ctl configtest
Syntax OK

3. $ sudo systemctl restart apache2

- When I typed http://zethanath.tk, I got "Unable to connect".
- When I typed http://www.zethanath.tk, I got "https://www.zethanath.tk/", and my GWT application is served correctly.
- When I typed http://servlet.zethanath.tk, I got "https://www.zethanath.tk/", and my GWT application is served correctly as well.

Later today, I will try to experiment by removing those ProxyPass setting, and using Mod JK instead. I have been reading some post online. People says Mod JK is better than ProxyPass as you can see below.

https://wiki.apache.org/tomcat/FAQ/Connectors

Thank you so much for your time.
 
Old 08-17-2017, 02:01 PM   #7
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
This was how I installed Mod JK and configured Mod JK.

1. sudo apt install libapache2-mod-jk

2. sudo nano /etc/libapache2-mod-jk/workers.properties

Code:
# workers.properties -
#
# This file is a simplified version of the workers.properties supplied
# with the upstream sources. The jni inprocess worker (not build in the
# debian package) section and the ajp12 (deprecated) section are removed.
#
# As a general note, the characters $( and ) are used internally to define
# macros. Do not use them in your own configuration!!!
#
# Whenever you see a set of lines such as:
# x=value
# y=$(x)\something
#
# the final value for y will be value\something
#
# Normaly all you will need to do is un-comment and modify the first three
# properties, i.e. workers.tomcat_home, workers.java_home and ps.
# Most of the configuration is derived from these.
#
# When you are done updating workers.tomcat_home, workers.java_home and ps
# you should have 3 workers configured:
#
# - An ajp13 worker that connects to localhost:8009
# - A load balancer worker
#
#

# OPTIONS ( very important for jni mode )

#
# workers.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
#
workers.tomcat_home=/opt/tomcat

#
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=/usr/lib/jvm/java-8-oracle/jre

#
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=/

#
#------ ADVANCED MODE ------------------------------------------------
#---------------------------------------------------------------------
#

#
#------ worker list ------------------------------------------
#---------------------------------------------------------------------
#
#
# The workers that your plugins should create and work with
#
worker.list=ajp13_worker

#
#------ ajp13_worker WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named ajp13_worker and of type ajp13
# Note that the name and the type do not have to match.
#
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
#  ----> lbfactor must be > 0
#  ----> Low lbfactor means less work done by the worker.
worker.ajp13_worker.lbfactor=1

#
# Specify the size of the open connection cache.
#worker.ajp13_worker.cachesize

#
#------ DEFAULT LOAD BALANCER WORKER DEFINITION ----------------------
#---------------------------------------------------------------------
#

#
# The loadbalancer (type lb) workers perform wighted round-robin
# load balancing with sticky sessions.
# Note:
#  ----> If a worker dies, the load balancer will check its state
#        once in a while. Until then all work is redirected to peer
#        workers.
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13_worker
3. sudo nano /opt/tomcat/conf/server.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <!-- TomEE plugin for Tomcat -->
  <Listener className="org.apache.tomee.catalina.ServerListener" />
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->
    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" xpoweredBy="false" server="Apache TomEE" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation with the JSSE engine. When
         using the JSSE engine, the JSSE configuration attributes must be used.

    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" xpoweredBy="false" server="Apache TomEE" />
        </SSLHostConfig>
    </Connector>
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the APR/native implementation. When using the
         APR/native implementation or the OpenSSL engine with NIO or NIO2 then
         the OpenSSL configuration attributes must be used.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" xpoweredBy="false" server="Apache TomEE" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                         certificateFile="conf/localhost-rsa-cert.pem"
                         certificateChainFile="conf/localhost-rsa-chain.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>
4. sudo systemctl restart tomcat

I started using Mod JK by using the following setup in the three files below.

$ sudo nano /etc/apache2/sites-available/default-ssl.conf
$ sudo nano /etc/apache2/sites-enabled/000-default.conf
$ sudo nano /etc/apache2/sites-enabled/000-default-le-ssl.conf


Code:
<VirtualHost _default_:443>
                ServerAdmin erick9.hi5@gmail.com
                ServerName  www.zethanath.tk
                ServerAlias servlet.zethanath.tk zethanath.tk

                Redirect permanent "/" "https://www.zethanath.tk/"

                #ProxyPreserveHost On
                #ProxyPass / http://192.168.1.70:8080/Index/
                #ProxyPassReverse / http://192.168.1.70:8080/Index/

                #DocumentRoot /var/www/html
                DocumentRoot /opt/tomcat/webapps/Index
                JkMountCopy On
                JKMount /* ajp13_worker

                # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
                # error, crit, alert, emerg.
                # It is also possible to configure the loglevel for particular
                # modules, e.g.
                #LogLevel info ssl:warn

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                ...
</VirtualHost>
- When I typed http://www.zethanath.tk, I got "https://www.zethanath.tk/", and "The page isn’t redirecting properly".
- When I typed http://servlet.zethanath.tk, I got "https://www.zethanath.tk/", and "The page isn’t redirecting properly" as well.

I hope someone can help.

Last edited by sethanath; 08-17-2017 at 02:27 PM. Reason: I forgot very important segtion.
 
Old 08-17-2017, 02:59 PM   #8
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
I tried the following setup in the three files below.

$ sudo nano /etc/apache2/sites-available/default-ssl.conf
$ sudo nano /etc/apache2/sites-enabled/000-default.conf
$ sudo nano /etc/apache2/sites-enabled/000-default-le-ssl.conf

Code:
<VirtualHost>

ServerAdmin erick9.hi5@gmail.com
ServerName  www.zethanath.tk
ServerAlias servlet.zethanath.tk zethanath.tk

Redirect permanent "/" "https://www.zethanath.tk/"

#ProxyPreserveHost On
#ProxyPass / http://192.168.1.70:8080/Index/
#ProxyPassReverse / http://192.168.1.70:8080/Index/

#DocumentRoot /var/www/html
DocumentRoot /opt/tomcat/webapps/Index/

Alias /Index "/opt/tomcat/webapps/Index/"
<Directory "/opt/tomcat/webapps/Index/">
  Options Indexes FollowSymLinks
  AllowOverride NONE
  Order allow,deny
  Allow from all
</Directory>

<Location "/Index/WEB-INF/">
  AllowOverride None
  Deny from all
</Location>

JKMountCopy On
JKMount /* ajp13_worker

...

</VirtualHost>
- When I typed http://www.zethanath.tk, I got "https://www.zethanath.tk/", and "The page isn’t redirecting properly".
- When I typed http://servlet.zethanath.tk, I got "https://www.zethanath.tk/", and "The page isn’t redirecting properly" as well.

I hope someone can help.

Last edited by sethanath; 08-18-2017 at 10:30 AM. Reason: Typo
 
Old 08-18-2017, 02:21 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
- When I typed http://zethanath.tk, I got "Unable to connect".
- When I typed http://www.zethanath.tk, I got "https://www.zethanath.tk/", and my GWT application is served correctly.
- When I typed http://servlet.zethanath.tk, I got "https://www.zethanath.tk/", and my GWT application is served correctly as well.
The 1st means that there is no IP for plain zethanath.tk. Maybe you've removed it from /etc/hosts
The other 2 responses mean that there is a loop in your config. Comment out (or remove) from inside the SSL vhost definition the
Code:
Redirect permanent "/" "https://www.zethanath.tk/"
The Redirect is supposed to be used for the non-SSL vhost in order to send clients to the SSL one
 
Old 08-18-2017, 10:29 AM   #10
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
The 1st means that there is no IP for plain zethanath.tk. Maybe you've removed it from /etc/hosts
That is correct. I really want to remove zethanath.tk, so that no one can use it. By using the two statements below, if the users typed servlet.zethanath.tk or zethanath.tk, they would be redirected to https://www.zethanath.tk. This is what I want all along.

Code:
ServerAlias servlet.zethanath.tk zethanath.tk
Redirect permanent "/" "https://www.zethanath.tk/"
Quote:
- When I typed http://www.zethanath.tk, I got "https://www.zethanath.tk/", and my GWT application is served correctly.
- When I typed http://servlet.zethanath.tk, I got "https://www.zethanath.tk/", and my GWT application is served correctly as well.

The other 2 responses mean that there is a loop in your config. Comment out (or remove) from inside the SSL vhost definition.
Are you sure there is a loop? the other two that you read are what I want as well In other words,

- When the users type http://www.zethanath.tk, they should be redirected to "https://www.zethanath.tk/".
- When the users type http://servlet.zethanath.tk, they should be redirected to "https://www.zethanath.tk/".

All three cases were configured successfully through the uses of Mod_Proxy.

However, I am hoping if someone can help me to do the same with Mod JK as well.
 
Old 08-18-2017, 04:08 PM   #11
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
- When I typed http://www.zethanath.tk, I got "https://www.zethanath.tk/", and my GWT application is served correctly.
- When I typed http://servlet.zethanath.tk, I got "https://www.zethanath.tk/", and my GWT application is served correctly as well.

The other 2 responses mean that there is a loop in your config. Comment out (or remove) from inside the SSL vhost definition.
Are you sure there is a loop? the other two that you read are what I want as well In other words,
Sorry didn't notice that you last posted it's served correctly. I was referring to post #8:
Quote:
- When I typed http://www.zethanath.tk, I got "https://www.zethanath.tk/", and "The page isn’t redirecting properly".
- When I typed http://servlet.zethanath.tk, I got "https://www.zethanath.tk/", and "The page isn’t redirecting properly" as well.
Anyway, so far so good


Quote:
All three cases were configured successfully through the uses of Mod_Proxy.

However, I am hoping if someone can help me to do the same with Mod JK as well.
AFAIK you have to put the mod_jk directives inside the SSL vhost stanza. I you want to see how to configure mod_jk, take a look here
 
Old 08-19-2017, 09:41 AM   #12
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Thank you.
 
Old 08-21-2017, 12:26 PM   #13
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Hi,

I believe I got really interesting results today. Here is the summary of what I think. You do not need to read previous post, but start from this one.

1. I believe Mod JK is the best way to accomplish https between Apache and TomEE. Please let me know your opinion, as I only know Mod Proxy and Mod JK at this point
2. Here is the content of /etc/apache2/sites-enabled/000-default.conf

Code:
<VirtualHost *:80 >
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerAdmin erick9.hi5@gmail.com
        ServerName  www.zethanath.tk
        ServerAlias servlet.zethanath.tk zethanath.tk

        Redirect permanent "/" "https://www.zethanath.tk/Index"

        #ProxyPreserveHost On
        #ProxyPass / http://192.168.1.70:8080/Index/
        #ProxyPassReverse / http://192.168.1.70:8080/Index/

        #DocumentRoot /var/www/html
        DocumentRoot "/opt/tomcat/webapps/Index"

        Alias /Index "/opt/tomcat/webapps/Index"
        <Directory "/opt/tomcat/webapps/Index">
          Options Indexes FollowSymLinks
          AllowOverride NONE
          Order allow,deny
          Allow from all
        </Directory>

        <Location "/Index/WEB-INF/">
          AllowOverride None
          Deny from all
        </Location>

        JKMountCopy On
        JKMount /* ajp13_worker

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
       # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.zethanath.tk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>
3. Here is the content of /etc/apache2/sites-available/default-ssl.conf

Code:
<IfModule mod_ssl.c>
   <VirtualHost _default_:443>
      ServerAdmin erick9.hi5@gmail.com
      ServerName  www.zethanath.tk
      ServerAlias servlet.zethanath.tk zethanath.tk

      Redirect permanent "/" "https://www.zethanath.tk/Index"

      #ProxyPreserveHost On
      #ProxyPass / http://192.168.1.70:8080/Index/
      #ProxyPassReverse / http://192.168.1.70:8080/Index/

      #DocumentRoot /var/www/html
      DocumentRoot "/opt/tomcat/webapps/Index"

      Alias /Index "/opt/tomcat/webapps/Index"
      <Directory "/opt/tomcat/webapps/Index">
         Options Indexes FollowSymLinks
         AllowOverride NONE
         Order allow,deny
         Allow from all
      </Directory>

      <Location "/Index/WEB-INF/">
         AllowOverride None
         Deny from all
      </Location>

      JKMountCopy On
      JKMount /* ajp13_worker

      # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
      # error, crit, alert, emerg.
      # It is also possible to configure the loglevel for particular
      # modules, e.g.
      #LogLevel info ssl:warn

      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined

      # For most configuration files from conf-available/, which are
      # enabled or disabled at a global level, it is possible to
      # include a line for only one particular virtual host. For example the
      # following line enables the CGI configuration for this host only
      # after it has been globally disabled with "a2disconf".
      #Include conf-available/serve-cgi-bin.conf

      #   SSL Engine Switch:
      #   Enable/Disable SSL for this virtual host.
      SSLEngine on

      #   A self-signed (snakeoil) certificate can be created by installing
      #   the ssl-cert package. See
      #   /usr/share/doc/apache2/README.Debian.gz for more info.
      #   If both key and certificate are stored in the same file, only the
      #   SSLCertificateFile directive is needed.
      SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
      SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
      Include /etc/letsencrypt/options-ssl-apache.conf

      #   Server Certificate Chain:
      #   Point SSLCertificateChainFile at a file containing the
      #   concatenation of PEM encoded CA certificates which form the
      #   certificate chain for the server certificate. Alternatively
      #   the referenced file can be the same as SSLCertificateFile
      #   when the CA certificates are directly appended to the server
      #   certificate for convinience.
      #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

      #   Certificate Authority (CA):
      #   Set the CA certificate verification path where to find CA
      #   certificates for client authentication or alternatively one
      #   huge file containing all of them (file must be PEM encoded)
      #   Note: Inside SSLCACertificatePath you need hash symlinks
      #          to point to the certificate files. Use the provided
      #          Makefile to update the hash symlinks after changes.
      #SSLCACertificatePath /etc/ssl/certs/
      #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt
      #   Certificate Revocation Lists (CRL):
      #   Set the CA revocation path where to find CA CRLs for client
      #   authentication or alternatively one huge file containing all
      #   of them (file must be PEM encoded)
      #   Note: Inside SSLCARevocationPath you need hash symlinks
      #          to point to the certificate files. Use the provided
      #          Makefile to update the hash symlinks after changes.
      #SSLCARevocationPath /etc/apache2/ssl.crl/
      #SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl

      #   Client Authentication (Type):
      #   Client certificate verification type and depth.  Types are
      #   none, optional, require and optional_no_ca.  Depth is a
      #   number which specifies how deeply to verify the certificate
      #   issuer chain before deciding the certificate is not valid.
      #SSLVerifyClient require
      #SSLVerifyDepth  10

      #   SSL Engine Options:
      #   Set various options for the SSL engine.
     #   o FakeBasicAuth:
      #  Translate the client X.509 into a Basic Authorisation.  This means that
      #  the standard Auth/DBMAuth methods can be used for access control.  The
      #  user name is the `one line' version of the client's X.509 certificate.
      #  Note that no password is obtained from the user. Every entry in the user
      #  file needs this password: `xxj31ZMTZzkVA'.
      #   o ExportCertData:
      #  This exports two additional environment variables: SSL_CLIENT_CERT and
      #  SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
      #  server (always existing) and the client (only existing when client
      #  authentication is used). This can be used to import the certificates
      #  into CGI scripts.
      #   o StdEnvVars:
      #  This exports the standard SSL/TLS related `SSL_*' environment variables.
      #  Per default this exportation is switched off for performance reasons,
      #  because the extraction step is an expensive operation and is usually
      #  useless for serving static content. So one usually enables the
      #  exportation for CGI and SSI requests only.
      #   o OptRenegotiate:
      #  This enables optimized SSL connection renegotiation handling when SSL
      #  directives are used in per-directory context.
      #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire

      <FilesMatch "\.(cgi|shtml|phtml|php)$">
         SSLOptions +StdEnvVars
      </FilesMatch>
      <Directory /usr/lib/cgi-bin>
         SSLOptions +StdEnvVars
      </Directory>

      #   SSL Protocol Adjustments:
      #   The safe and default but still SSL/TLS standard compliant shutdown
      #   approach is that mod_ssl sends the close notify alert but doesn't wait for
      #   the close notify alert from client. When you need a different shutdown
      #   approach you can use one of the following variables:
      #   o ssl-unclean-shutdown:
      #  This forces an unclean shutdown when the connection is closed, i.e. no
      #  SSL close notify alert is send or allowed to received.  This violates
      #  the SSL/TLS standard but is needed for some brain-dead browsers. Use
      #  this when you receive I/O errors because of the standard approach where
      #  mod_ssl sends the close notify alert.
      #   o ssl-accurate-shutdown:
      #  This forces an accurate shutdown when the connection is closed, i.e. a
      #  SSL close notify alert is send and mod_ssl waits for the close notify
      #  alert of the client. This is 100% SSL/TLS standard compliant, but in
      #  practice often causes hanging connections with brain-dead browsers. Use
      #  this only for browsers where you know that their SSL implementation
      #  works correctly.
      #   Notice: Most problems of broken clients are also related to the HTTP
      #   keep-alive facility, so you usually additionally want to disable
      #   keep-alive for those clients, too. Use variable "nokeepalive" for this.
      #   Similarly, one has to force some clients to use HTTP/1.0 to workaround
      #   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
      #   "force-response-1.0" for this.
      # BrowserMatch "MSIE [2-6]" \
      #         nokeepalive ssl-unclean-shutdown \
      #         downgrade-1.0 force-response-1.0

   </VirtualHost>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
4. Here is the content of /etc/apache2/sites-enabled/000-default-le-ssl.conf

Code:
<IfModule mod_ssl.c>
   <VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerAdmin erick9.hi5@gmail.com
        ServerName  www.zethanath.tk
        ServerAlias servlet.zethanath.tk zethanath.tk

        Redirect permanent "/" "https://www.zethanath.tk/Index"

        #ProxyPreserveHost On
        #ProxyPass / http://192.168.1.70:8080/Index/
        #ProxyPassReverse / http://192.168.1.70:8080/Index/

        #DocumentRoot /var/www/html
        DocumentRoot "/opt/tomcat/webapps/Index"

        Alias /Index "/opt/tomcat/webapps/Index"
        <Directory "/opt/tomcat/webapps/Index">
          Options Indexes FollowSymLinks
          AllowOverride NONE
          Order allow,deny
          Allow from all
        </Directory>

        <Location "/Index/WEB-INF/">
          AllowOverride None
          Deny from all
        </Location>

        JKMountCopy On
        JKMount /* ajp13_worker
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

        SSLCertificateFile /etc/letsencrypt/live/zethanath.tk/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/zethanath.tk/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

  </VirtualHost>
</IfModule>
- When I typed http://www.zethanath.tk, I got https://www.zethanath.tk/IndexIndexI...ndexIndexIndex
- When I typed http://servlet.zethanath.tk, I got https://www.zethanath.tk/IndexIndexI...ndexIndexIndex also.

My questions are below.

1. How do I fix that?
2. What I have problems with are the begin "/" and the end "/" in the three files above. How do I use this "/" in the configuration files.

<VirtualHost .......>

Redirect permanent "/" "https://www.zethanath.tk/Index" --> Should I end this line with "/" and make it be https://www.zethanath.tk/Index/?

DocumentRoot "/opt/tomcat/webapps/Index" --> When should I start or end this line with "/"? --> DocumentRoot "/opt/tomcat/webapps/Index/"

Alias /Index "/opt/tomcat/webapps/Index" --> When should I start or end this line with "/"? --> Alias /Index "/opt/tomcat/webapps/Index/"
<Directory "/opt/tomcat/webapps/Index"> --> When should I start or end this line with "/"? --> <Directory "/opt/tomcat/webapps/Index/">
...
</Directory>

<Location "/Index/WEB-INF/"> --> When should I start or end this line with "/"? --> <Location "/Index/WEB-INF/">
...
</Location>

</VirtualHost .......>

Last edited by sethanath; 08-21-2017 at 12:38 PM. Reason: Typo
 
Old 08-22-2017, 02:21 AM   #14
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
1. I believe Mod JK is the best way to accomplish https between Apache and TomEE. Please let me know your opinion, as I only know Mod Proxy and Mod JK at this point
I'm always using apache as a reverse proxy, even though mod_jk is faster, because it's easier to configure.


Quote:
2. Here is the content of /etc/apache2/sites-enabled/000-default.conf
Told you many times that you only need the Redirect in the http vhost (without the /Index/ part)
Code:
<VirtualHost *:80 >
        ServerAdmin erick9.hi5@gmail.com
        ServerName  www.zethanath.tk
        ServerAlias servlet.zethanath.tk zethanath.tk
        Redirect permanent "/" "https://www.zethanath.tk/"
</VirtualHost>

Quote:
3. Here is the content of /etc/apache2/sites-available/default-ssl.conf
<snip>
4. Here is the content of /etc/apache2/sites-enabled/000-default-le-ssl.conf
<snip>
I'm not familiar with ubuntu apache config style, but AFAIK, you only edit one of those files (besides the latter should be a symlink of the former).


You have a loop, because as I've already told you many times, you don't need a Redirect in the SSL vhost!!!! Please pay attention to what I'm suggesting to you.


Quote:
My questions are below.

1. How do I fix that?
2. What I have problems with are the begin "/" and the end "/" in the three files above. How do I use this "/" in the configuration files.
1. See the answer above
2. The "/" is important only in Redirect, Alias, and such. If you use a trailing "/" at the end of a URI at the left, you need also to use one at the URI on the right.
The trailing "/" is not important in a <Directory...>, or DocumentRoot, but I suggest you to read apache documentation for more details.
 
Old 08-22-2017, 11:45 AM   #15
sethanath
LQ Newbie
 
Registered: Aug 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Hi,

Quote:
Told you many times that you only need the Redirect in the http vhost (without the /Index/ part)
Code:
I removed the /Index/ part, just like you suggested.

Code:
<VirtualHost *:80 >
   ServerName  www.zethanath.tk
   ServerAlias servlet.zethanath.tk zethanath.tk

   Redirect permanent "/" "https://www.zethanath.tk/"

   DocumentRoot "/opt/tomcat/webapps/Index"

   Alias /Index "/opt/tomcat/webapps/Index"
   <Directory "/opt/tomcat/webapps/Index">
     Options Indexes FollowSymLinks
     AllowOverride NONE
     Order allow,deny
     Allow from all
   </Directory>

   <Location "/Index/WEB-INF/">
     AllowOverride None
     Deny from all
   </Location>
</VirtualHost>
I also removed the redirect from the https vhost.

Code:
<IfModule mod_ssl.c>
   <VirtualHost _default_:443>
      ServerAdmin erick9.hi5@gmail.com
      ServerName  www.zethanath.tk
      ServerAlias servlet.zethanath.tk zethanath.tk

      DocumentRoot "/opt/tomcat/webapps/Index"

      Alias /Index "/opt/tomcat/webapps/Index"
      <Directory "/opt/tomcat/webapps/Index">
         Options Indexes FollowSymLinks
         AllowOverride NONE
         Order allow,deny
         Allow from all
      </Directory>

      <Location "/Index/WEB-INF/">
         AllowOverride None
         Deny from all
      </Location>
   </VirtualHost>
</IfModule>
Here are the results that I have.

- When I typed "http://www.zethanath.tk" in the browser, I would get "https://www.zethanath.tk/" with HTTP Status 404 The requested resource is not available.
- When I typed "http://servlet.zethanath.tk" in the browser, I would get "https://www.zethanath.tk/" with HTTP Status 404 The requested resource is not available too.

If I am not mistaken, what I need is to associate port 8080 with "DocumentRoot". I need to be able to do something like this.

DocumentRoot "/opt/tomcat/webapps/Index:8080".

Thank you so much.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apache 2.0 https to https redirect struct Linux - Software 1 04-22-2011 05:43 PM
Redirect https apache requests to folder not in apache root bax Linux - Enterprise 4 04-12-2010 01:16 PM
Can't configure Apache to serve https on alternate port lostjohnny Linux - Server 6 10-30-2009 12:47 PM
How do you properly redirect all web client requests from http to https? mehoggan Linux - Server 4 06-02-2009 03:49 AM
LXer: Linux configure pound reverse proxy for Apache http / https web server LXer Syndicated Linux News 0 12-14-2007 07:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration