Webpack 3 devserver hot module replacement through apache mod_proxy - apache

I have a project where we use webpack's devserver for local development. We also have the hot module replacemet for live reload: hot module replacement
We have our front end running in docker. With that front end, we have also apache's mod_proxy. Idea is to have all http call's to go through the mod_proxy. So browser will send http to mod_proxy, that will then proxy to front end. This works well without hot module replacement. But for some reason, we are unable to get the hot module replacement work. I guess it is because hot module replacement uses web sockets, and tunneling web socket call's through apache's mod_proxy is not enabled by default?
Has someone been able to achieve this? How did you manage to do it? What configurations were needed in devserver / hot module replacement? Did you use apache's mod_proxy web socket tunnel: mod_proxy_wstunnel, and how did you configure it? You do not need to answer to all the sub questions listed before, I just need the info on how to get it working.

A. Yes. I could get this working with the following configuration in Apache2
<Location /sockjs-node>
RequestHeader set Host "localhost:4200"
RequestHeader set Origin "http://localhost:4200"
ProxyPass ws://localhost:4200/sockjs-node
ProxyPassReverse ws://localhost:4200/sockjs-node
CacheDisable on
</Location>
<Location /sockjs-node/info>
ProxyPass http://localhost:4200/sockjs-node/info
ProxyPassReverse http://localhost:4200/sockjs-node/info
CacheDisable on
</Location>
B. My apache2 server has mod_proxy and mod_proxy_wstunnel enabled.
C. I am using this configuration for my angular 7 development.

Related

Mojolicious url_for operation insecure in webservice

I am trying to return content with a web service. Behind an apache proxy if fails with "Operation insecure".
I read about adding an apache hook but it won't work for me. Setting the environment variable neither.
This is what I tried: how to make Mojolicious's url_for()->to_abs() return correct scheme (http or https) behind nginx
Maybe or webservice I have to do something else ? Also I use mojolicious lite.
Also the url_for is done in the template file .html.ep. I use it to call the web service from javascript.
I run Mojolicious 7.59 on Ubuntu 18.04. Thank you for you help
I solved it this way: the apache proxy must have some specific settings and also the mojo app must be in reverse proxy mode.
Apache Settings
Apache must know how to proxy the web services and it must tell mojo about the forwarding protocol.
I put all my webservices under the /ws/ and I added it to ProxyPass
My mojo app is at the same host at port 8080 so I proxy to localhost:8080.
It is very important to set the X-Forwarded-Proto
At /etc/apache2/sites-enabled/default-ssl.conf I changed this way:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /ws/ ws://localhost:8080/ws/ keepalive=On
ProxyPass / http://localhost:8080/ keepalive=On
ProxyPassReverse / http://localhost:8081/
RequestHeader set X-Forwarded-Proto "https"
Mojo Proxy
The mojolicious app must know it is in reverse proxy. If you are using hypnotoad it may not be necessary. When I did some tests with morbo I had to run it this way:
MOJO_REVERSE_PROXY=1 morbo script.pl
There is more documentation at https://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#Reverse-proxy

Apache redirect with a relative path

I want to clear a doubt, it's possible in Apache to make "Alias" (Mask) to another port ??
Let I make a use of example:
In my Server I have Apache running in *:80 and another application running *:8080, Inside a domain called www.example.com.
So, What I'm think is if is possible and how can I do to make a "ALIAS" to if I use www.example.com\other to redirect to www.example.com:8080\gui.
And it is possible to mask this name to be example.com\other?
As said, I've enabled mod_proxy to use ProxyPass and ProxyPassReverse
This was my first try with ProxyPass
ProxyPass /foo http://domain.com:5780
ProxyPassReverse /foo http://domain.com:5780
When I tried to access http://myown.com/foo it redirected to the domain selected but did not loaded the images, I did not saw that before because the images are at the page bottom.
I have read some page about mod_rewrite, mod_alias, redirect and mod_proxy, I've edited my apache config and it's not working properly.
The answer depends on what application is running on port 8080.
If it's a Java application running under Tomcat, consider mod_jk
If it's a Python WSGI application, consider modwsgi in daemon mode.
You could also use mod_proxy (eg. Apache mod_rewrite internally to different port).

Apache httpd as load balancer for jboss as well another Apache servers

I have an apache httpd server, say server1* (publicly exposed) that is acting as load balancer for some jboss servers(behind firewall) using mod_cluster. Now I want to install my static content (images/css/htmls) and probably some cg-scripts on a couple of apache servers, say **server2 and server3 (behind firewall).
Now I want server1 to act as load balancer for these server2 and server3 as well along with the jboss servers.
With this arrangement, any request for applications deployed on jboss need to be routed to jboss and any static content request should go to server2 or server3.
Here are the versions I am using
Linux Server
apache httpd - 2.2.22
JBOSS-EAP-6
What mechanism/configuration do I need to use in server1 to make it possible?
Please see if someone can help with this.
Well, you just add a ProxyPass setting. mod_cluster is compatible with ProxyPass, so you can use both.
For instance, if I would like gif images to be served by httpd, not by AS7, I can add:
ProxyPassMatch ^(/.*\.gif)$ !
Furthermore, if you set
CreateBalancers 1
mod_cluster won't create proxies for you and you have to do it yourself. This gives you an additional control. For instance:
ProxyPassMatch ^/static/ !
ProxyPass / balancer://qacluster stickysession=JSESSIONID|jsessionid nofailover=on
ProxyPassReverse / balancer://qacluster
ProxyPreserveHost on
In the aforementioned example, we proxy anything but /static/ content to the workers.
Note:If you encounter any cookies related issues, you might want to play with ProxyPassReverseCookieDomain and ProxyPassReverseCookiePath.
Note qacluster in my config. The default is mycluster, so for naming my balancer qacluster, I added this to mod_cluster config (outside VirtualHost):
ManagerBalancerName qacluster
If it is not clear, just reply and I can try to elaborate further.
I had the same issue where in we were using Apache HTTP server for static content and JBOSS AS 7 server for dynamic contents (the JSF web app).
So adding the below property at the end of Load modules tells
CreateBalancers 0
Tells to "0: Create in all VirtualHosts defined in httpd."
More at: http://docs.jboss.org/mod_cluster/1.2.0/html/native.config.html#d0e485
And the below config solved the issues of images and styel sheets not getting displayed.
<VirtualHost *:80>
ServerName dev.rama.com
DocumentRoot "/var/www/assests"
UseAlias 1
ProxyPassMatch ^(.*\.bmp)$ !
ProxyPassMatch ^(.*\.css)$ !
ProxyPassMatch ^(.*\.gif)$ !
ProxyPassMatch ^(.*\.jpg)$ !
ProxyPassMatch ^(.*\.js)$ !
ProxyPassMatch ^(.*\.png)$ !
<Directory /var/www/assests>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Note:
All our assests for the web app was on HTTP server at
/var/www/assests and the url I was accessing was dev.rama.com on port 80
So when it sees this ProxyPassMatch ^(.*.css)$ !
The webserver knows that the css files are local to the http server and we dont need to go to Jboss App server.
More info at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass

Apache Webserver configuration to multiple apache tomcat application

I have apache tomcat application which is configured to apache webserver, now I want to add another apache tomcat application to same Apache web server,all these servers (apache tomcat and apache web server (rhel)) are on same network, kindly provide me some ways for configuring it.
is there any other way without using mod_jk?
Apache can talk to Tomcat using either mod_jk or by using the standard proxy module, mod_proxy. Using the standard proxy module, it's very easy to put multiple instances of Tomcat behind a single Apache instance.
Assuming that you have a Tomcat instance listening on port 8080 and another on port 8081, you can do something as simple as this:
<Location /app1/>
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/
</Location>
<Location /app2/>
ProxyPass http://localhost:8081/
ProxyPassReverse http://localhost:8081/
</Location>
This places the first instance at /app1/ and the second instance at
/app2/.
The mod_proxy documentation is a good place to start, and the tomcat documentation covers this topic briefly.

Tomcat Manager with mod_proxy and ROOT web application

Our application runs in Tomcat6 and we're proxying all requests from Apache to Tomcat via mod_proxy. that proxy config looks like:
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
<Location />
Order deny,allow
Allow from all
</Location>
Our application is also deployed as ROOT. I think that this is causing issues when attempting to get to the /manager URL but I'm not 100% sure and unclear on how I can verify this. Can anyone give me some pointers on how to resolve this? I'd like to use the manager app for remote deployments from jenkins.
That configuration will route all traffic to Tomcat, including requests to /manager. The way to confirm this is to look at Tomcat's access log that should show the same requests as httpd's access log.
Try http:// localhost/manager/html
It should work on both ports.