skip to Main Content

This question is probably too simple but I cannot get it to work despite hours of testing (and even crashing the server twice o.o ).

The issue is asked frequently: A Tomcat server is accessible through:
“domain.net:8080/theserver/”
and I want it to be accessible directly on “domain.net/”.
Just that should also be visible in the user’s browser.

The engine “Plesk” which I’m using to configure the site offers a command field for such things. Using the following lines, I’ve established visible redirecting:

ProxyRequests off
RequestHeader      unset  Accept-Encoding
RewriteEngine     on
RewriteRule ^(/.*)      http://www.domain.net:8080/theserver [P]

The redirection doesn’t happen in the background though. When I type domain.net into the browser, it switches to “domain.net:8080/theserver/”.

What’s the right way to make this happen in the background?
“theserver” is the root-location which should be accessible on the server for now.

Huge thanks in advance!

5

Answers


  1. If you control the apache web server, then do you not have to redirect any URL.
    Rewriting is supposed to happen for unique requests. If possible, then should the type of rewrite you want get done in the configuration of apache.

    First do you have to tell the apache server to listen on port 8080:

    listen 8080
    

    Then can you make a virtual host like this:

    <VirtualHost *.:8080>
       Servername www.domain.net
    </VirtualHost>
    

    See for instance:
    https://httpd.apache.org/docs/trunk/vhosts/examples.html
    and
    https://httpd.apache.org/docs/trunk/vhosts/examples.html#port
    specifically.

    This is much more efficient than using .htaccess, because the latter is parsed at every request, where the solution with virtual hosts is loaded into memory during startup of the server.

    Your solution is the other way around. It will make the port visible, because that is the rewrite you create. You want it the other way around and that can be established best by making use of virtual hosts.

    A little example of a virtual host:

    <VirtualHost www.example.nl:8080>
       ServerName www.example.nl
       ServerAlias example.nl
       DocumentRoot /var/www/theserver
       <Directory /var/www/theserver>
         etc..
       </Directory>
       etc...
    </VirtualHost>
    
    Login or Signup to reply.
  2. You first need to make sure both mod_proxy and mod_proxy_http are enabled in plesk.

    Also you should probably either use www or not www.

    ProxyRequests Off
    RewriteEngine on
    RewriteRule ^(.*)$ http://domain.net:8080/myserver/$1 [P]
    

    You can also use the ProxyPass in the server config/vhost.

      <Location />
        ProxyPass http://domain.net:8080/
        ProxyPassReverse http://domain.net:8080/
      </Location>
    
    Login or Signup to reply.
  3. You’re just missing ProxyPassReverse. The backend is sending a redirect on the initial URL to add a trailing slash. ProxyPassReverse fixes those redirects for you to use the frontend host/port.

    Login or Signup to reply.
    1. Make sure Rewrite Module of webserver is enabled.
    2. Make sure apache listens on port 80 and 8080 both.
    3. Add this to .htaccess file in the root BUT NOT in the subdirectory “theserver”.

      RewriteEngine on

      RewriteCond %{HTTP_HOST} ^(www.)?domain.net$

      RewriteCond %{REQUEST_URI} !^/theserver/

      RewriteCond %{REQUEST_FILENAME} !-f

      RewriteCond %{REQUEST_FILENAME} !-d

      RewriteRule ^(.*)$ http://domain.net:8080/theserver/$1

      RewriteCond %{HTTP_HOST} ^(www.)?domain.net$

      RewriteRule ^(/)?$ http://domain.net:8080/theserver/index.php [L]

    Login or Signup to reply.
  4. You may want to actually setup ProxyPass and ProxyPassReverse to accomplish what you are trying to do

    ProxyRequests on
    
    ProxyPass /      http://IP_OR_LOCALHOST:8080/theserver/
    ProxyPassReverse /      http://IP_OR_LOCALHOST:8080/theserver/
    
    OR
    
    ProxyPass /theserver/      http://IP_OR_LOCALHOST:8080/theserver/
    ProxyPassReverse /theserver/      http://IP_OR_LOCALHOST:8080/theserver/
    
    OR
    
    ProxyPass /anyname/      http://IP_OR_LOCALHOST:8080/theserver/
    ProxyPassReverse /anyname/      http://IP_OR_LOCALHOST:8080/theserver/
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search