Search code examples
http-redirectapache2proxypass

Can't redirect to another website running on different port


I've two sites serving on port 8080 1) localhost:8080 -> mainsite 2) localhost:8080/foo -> foosite

I've placed all the folders in /var/www/html

Now I've another node.js website running on port 7777

If i received a request localhost:8080/survey-> this should redirect to localhost:7777/examples/react

But it is redirected to localhost:8080/examples/react

I've enabled proxy and proxy_http and added the required proxy Paths

<VirtualHost *:8090>    
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ProxyPass /survey http://localhost:7777/examples/react
    ProxyPassReverse /survey http://localhost:7777/examples/react
</VirtualHost>

Solution

  • Try with load modules:

    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    <VirtualHost *:8090>    
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        ProxyPass /survey http://localhost:7777/examples/react
        ProxyPassReverse /survey http://localhost:7777/examples/react
    </VirtualHost>
    

    Also you should leave out the domain http://localhost:7777 in ProxyPass and ProxyPassReverse and leave it as /