Score:0

Apache proxypass css/js to their specific URLs

cn flag

I have two of my backend sockets running at port 9000 and 9001. Both provide a WebUI with CSS,JS and PHP. But both are different websites and when I use proxypass for both sites, how can I load css,js from the requested URL itself?

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin [email protected]
        ProxyRequests off
        DocumentRoot /var/www/html
        SSLProxyEngine on
        ProxyPreserveHost On
        SSLProxyVerify none
        SSLProxyCheckPeerCN off
        SSLProxyCheckPeerName off
        SSLProxyCheckPeerExpire off
#       ServerName _

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
        LogLevel error

        SSLEngine on
        SSLCertificateFile /path/to/crt
        SSLCertificateKeyFile /path/to/key


        RewriteEngine on
        RewriteRule ^/site1$ /site1/ [R]

        ProxyPass /site1/  https://127.0.0.1:9000/
        ProxyPass /vendor/  https://127.0.0.1:9000/vendor
        ProxyPass /css/  https://127.0.0.1:9000/css
        ProxyRequests off
        ProxyHTMLURLMap https://127.0.0.1:9000/  /site1/
        ProxyHTMLExtended On
        <Location /site1/>
            ProxyPassReverse /
            ProxyHTMLEnable On
            ProxyPreserveHost On
            ProxyHTMLURLMap  /  /site1/
            RequestHeader    unset  Accept-Encoding
        </Location>

        RewriteRule ^/site2$ /site2/ [R]

        ProxyPass /site2/  https://127.0.0.1:9001/
        ProxyPass /vendor/  https://127.0.0.1:9001/vendor
        ProxyPass /css/  https://127.0.0.1:9001/css
        ProxyRequests off
        ProxyHTMLURLMap https://127.0.0.1:9001/  /site2/
        ProxyHTMLExtended On
        <Location /site2/>
            ProxyPassReverse /
            ProxyHTMLEnable On
            ProxyPreserveHost On
            ProxyHTMLURLMap  /  /site2/
            RequestHeader    unset  Accept-Encoding
        </Location>

</VirtualHost>

As you can see above, I have added

ProxyPass /vendor/  https://127.0.0.1:9000/vendor
ProxyPass /css/  https://127.0.0.1:9000/css

both these lines to manually pass the CSS,vendor files to the proxy URL. But how can I make the same to site2? Since /css is added above, in site2 am getting css content from site1 itself. Also to make all hyperlinks in the site have the /site1/ and /site2/ path, I have added ProxyHTMLURLMap / /site2/ line in both of them. Its working. But no sure why CSS, JS files still go to / root path since root path doesn't have any files and give 404. How can I make these internal call CSS,JS files also take prefix /site1/ or /site2/

Without any of the ProxyHTMLURLMap / /site2/ all the links give 404 since requests go for / instead of /site2/ Same thing I want to do for CSS/JS files as well.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.