Sending redirect in Tomcat web application behind a Apache 2 proxy (mod_proxy)

前端 未结 5 697
攒了一身酷
攒了一身酷 2021-01-01 18:20

I have a web application on tomcat http://localhost:8080/WebApp/

The I have configrued Apache 2 (mod_proy) so that the web application is directly acces

5条回答
  •  时光取名叫无心
    2021-01-01 18:46

    I had the same problem while tried to redirect the apache2(running on port 80) request to tomcat(application server running on port 8080).

    This is the configuration which is working perfectly.

    Go to /etc/apache2/sites-available/000-default.conf and add the following config:

    
        # 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.example.com
    
        # for redirecting the websocket requests
        ProxyPass /ws ws://localhost:7681/ 
        #ProxyPass  /ws ws://localhost:7681/
    
        ProxyPassReverse   /ws ws://localhost:7681/
    
        ServerAdmin webmaster@localhost
        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
    
        # 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
    
    
    # for redirecting the http request 
       ProxyPass /applicationContextUrl                         '  http://localhost:8080/applicationContextUrl
    
       ProxyPassReverse /applicationContextUrl         http://localhost:8080/applicationContextUrl
    
       ProxyPassReverseCookiePath /applicationContextUrl / 
       ProxyPassReverseCookieDomain localhost applicationContextUrl
       ProxyRequests off
       ProxyTimeout 15
    
    
       ErrorLog ${APACHE_LOG_DIR}/nirad_error.log
       LogLevel debug
    CustomLog ${APACHE_LOG_DIR}/nirad_access.log combined
    
           AddDefaultCharset off
           Order deny,allow
           Allow from all
           #Require all denied
           Require all granted
           Require local
    
    
    
    

    Done. Now goto terminal and hit the following command.

    1. sudo a2enmod proxy_http (for http redirection).
    2. sudo a2enmod proxy_wstunnel (for websocket redirection)
    3. and sudo service apache2 restart
    4. run your application server on port 8080

提交回复
热议问题