How to redirect Apache to different ports on a GlassFish server?
Instead of using ajp, I would recommend using mod_proxy. I have done that myself with great success. The way I have my stuff set up, I just configure a virtual domain to point to a directory, and create a .htaccess file as such:
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
Of course, alter to match your HTTP ports. In tomcat (which I use), I also edit in server.xml under conf. For the Connector on port 8080, I set the proxyName to match the virtual host, and the proxyPort to 80.
I should add a note that I am using dynamic virtual hosts for my configuration, my sites configuration (I am using debian) under /etc/apache2/sites-available looks as such:
<VirtualHost IP>
Servername yourdomain.com
ServerAlias *.yourdomain.com
UseCanonicalName Off
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog /var/www/yourdomain.com/logs/custom.log vcommon
ErrorLog /var/www/yourdomain.com/logs/error.log
TransferLog /var/www/yourdomain.com/logs/access.log
RewriteLog/var/www/yourdomain.com/logs/rewrite.log
RewriteLogLevel 2
VirtualDocumentRoot /var/www/yourdomain.com/sites/%1/html
VirtualScriptAlias /var/www/yourdomain.com/sites/%1/cgi-bin
LogLevel debug
<Directory /var/www/yourdomain.com/sites/>
AllowOverride All
</Directory>
</VirtualHost>
This means that stackoverflow.yourdomain.com will go to /var/www/yourdomain.com/sites/stackoverflow/html
I know you didn't ask for the last part, I just provided it to give a full overview off my setup, and how it fits into the .htaccess file with ProxyPass and ProxyPassReverse
Related videos on Youtube
Admin
Updated on September 17, 2022Comments
-
Admin over 1 year
I have a GlassFish instance running different services on different ports. An Apache web server sits in front of the GlassFish, and I want to set up virtual hosts on Apache to redirect to certain ports on the GlassFish server.
I've added the Tomcat AJP as a jvm-option to listen on port 8009 and placed the necessary .jars under lib/.
How can I configure GlassFish to redirect from port 8009 to a given port (service) on the same instance?
-
Admin almost 15 yearsWe're using mod_proxy over AJP in place also. I find it much more straightforward to setup. What are the benefits of AJP (if any) I wonder? Is it better from a performance perspective?