Apache: rewrite url in background

This question is probably too simple, but I can't get it to work despite hours of testing (and even server crashing twice oo).

The question is often asked: the Tomcat server is accessible through: "Domain.net:8080/theserver/" and I want it to be available directly on "domain.net/". This should also be visible in the user's browser.

The Plesk engine, which I use to set up the site, offers a command box for such things. Using the following lines, I set the visible redirection:

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

However, redirection is not performed in the background. When I enter domain.net into the browser, it switches to "domain.net:8080/theserver/".

What is the right way to do this in the background? "theserver" is the root location that should now be available on the server.

Thank you so much in advance!

+4
source share
5 answers
  • Ensure that the Rewrite Module of the web server is enabled.
  • Make sure apache is listening on port 80 and 8080 both.
  • Add this to the .htaccess file in the root, BUT NOT in the "theserver" subdirectory.

    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]

+3

, mod_proxy mod_proxy_http.

, , www www.

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

ProxyPass /vhost.

  <Location />
    ProxyPass http://domain.net:8080/
    ProxyPassReverse http://domain.net:8080/
  </Location>
+2

ProxyPassReverse. URL, . ProxyPassReverse /.

+2

- apache, - URL-. , . , , apache.

apache 8080:

listen 8080

:

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

. : https://httpd.apache.org/docs/trunk/vhosts/examples.html https://httpd.apache.org/docs/trunk/vhosts/examples.html#port .

, .htaccess, , .

- . , , . , , , .

:

<VirtualHost www.example.nl:8080>
   ServerName www.example.nl
   ServerAlias example.nl
   DocumentRoot /var/www/theserver
   <Directory /var/www/theserver>
     etc..
   </Directory>
   etc...
</VirtualHost>
+1

, ProxyPass ProxyPassReverse, ,

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/
0

Source: https://habr.com/ru/post/1617946/


All Articles