Problem rewrite url apache to nodeJS with mod_cluster willdfly - node.js

I have apache with mod_cluster for wildfly cluster
I have one virtualhost on 443
I have a nodeJS on 8443 on same server apache
I want to redirect server/api to server:8443 (nodejs)
NODEJS and apache are on same server (apache 443 ,nodejs 8443)
<VirtualHost ip:443>
ServerName server
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLEngine on
SSLCipherSuite ALL:!MD5:!EXPORT:!DES:!3DES:!DHE:!EDH:!RC4:!aNULL:!eNULL:!MEDIUM:!LOW
SSLCertificateFile /etc/httpd/certs/newcert.pem
SSLCertificateKeyFile /etc/httpd/certs/newkey.pem
SSLCertificateChainFile /etc/httpd/certs/newcert.pem
<Directory />
Require all granted
</Directory>
<Location /mcm>
SetHandler mod_cluster-manager
Order Allow,Deny
Allow from all
</Location>
AllowDisplay On
AllowCmd Off
KeepAliveTimeout 180
TimeOut 300
***SSLProxyEngine on
ProxyRequests Off
<Location /api>
ProxyPreserveHost On
ProxyPass https://server:8443
ProxyPassReverse https://server:8443
</location>***
<Location /status>
SetHandler server-status
</Location>
The part between ******* does not work and other application make a not found. i don't know how to achieve it.. have the load balancer , and the virtualhost in front of node JS
If i delete this part it work for all applications on the wildfly cluster
Any Idea ?

simply add / at the end of the url
<VirtualHost ip:443>
ServerName server
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLEngine on
SSLCipherSuite ALL:!MD5:!EXPORT:!DES:!3DES:!DHE:!EDH:!RC4:!aNULL:!eNULL:!MEDIUM:!LOW
SSLCertificateFile /etc/httpd/certs/newcert.pem
SSLCertificateKeyFile /etc/httpd/certs/newkey.pem
SSLCertificateChainFile /etc/httpd/certs/newcert.pem
<Directory />
Require all granted
</Directory>
<Location /mcm>
SetHandler mod_cluster-manager
Order Allow,Deny
Allow from all
AllowDisplay On
AllowCmd Off
KeepAliveTimeout 180
TimeOut 300
SSLProxyEngine on
ProxyRequests Off
<Location />
ProxyPreserveHost On
ProxyPass https://server:8443/
ProxyPassReverse https://server:8443/
</location>
<Location /status>
SetHandler server-status
</Location>
and in my case location must be / otherwise it does'nt work

Related

How to configure apache to forward https requests to a Strapi/node application running on port 1337?

I have a Strapi/node js application running on port 1337, and I can reach it with:
http://my-ip:1337
I also have a domain associated in the same server and a working ssl certificate in apache2, so that in the browser I can use https:
https://my-domain.com
Now, when I try to use https to reach port 1337 like this:
https://my-domain.com:1337
I get an "This site can’t provide a secure connection" error.
I tried to edit my my-domain.ssl.conf in apache 2 with the following code:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.my-domain
ServerAlias my-domain
DocumentRoot /var/www/my-domain/public_html
ErrorLog /var/www/my-domain/log/error.log
CustomLog /var/www/my-domain/log/requests.log combined
SSLProxyEngine On
ProxyPreserveHost On
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/my-domain/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/my-domain/privkey.pem
</VirtualHost>
</IfModule>
But unluckily when I introduce the ProxyPass directive the server stops working without any meaningful error.
Both mod_proxy and mod_proxy_http are loaded in the apache2 configuration..
What could be the problem here? Thanks to anyone who can help with it!!
Strapi/node js application running on port 1337 to https
1st Changes
Edit /etc/apache2/sites-available/000-default.conf
ServerName yourdomian-name.com
ProxyPreserveHost On
SSLProxyEngine On
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
ProxyPreserveHost On
SSLCertificateFile /etc/letsencrypt/live/yourdomian-name.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomian-name.com/privkey.pem
2nd Changes
Edit this /etc/apache2/sites-available/000-default-le-ssl.conf
SSLCertificateFile /etc/letsencrypt/live/yourdomian-name.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomian-name.com/privkey.pem
ServerName yourdomian-name.com
ProxyPreserveHost On
SSLProxyEngine On
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
ProxyPreserveHost On
then restart apache2
sudo /etc/init.d/apache2 restart
Check https://yourdomian-name.com

Using wordpress for /blog route in nodejs website not working

I created a vhost like this in my apache2 server configuration:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName test.co
ServerAdmin webmaster#localhost
#wordpress
Alias /blog "/var/www/test_wp/public_html"
<Directory "/var/www/test_wp/public_html">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
SSLCertificateFile /etc/letsencrypt/live/test.co/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.co/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
I'm using alias to redirect /blog url (test.co/blog) to wordpress folder in my server.
i'm using proxypass for the nodejs website.
But when i hit test.co/blog , it shows 404 not found, in my nodejs website
Follow this: Exclude an alias from virtualhost proxypass
Add this line :
ProxyPassMatch ^/blog !
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

Serving a NodeJS app via apache

I am running a nodejs application on my apache2 web server. On trying to access the domain page example.com it shows the default apache page instead of the apps page. But on going to example.com:8090 it show the node application
This is the config
<VirtualHost *80>
ServerName example.com
ServerAlias www.example.com
ProxyRequests off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://serverip:8090
ProxyPassReverse http://serverip:8090
</Location>
</VirtualHost>
This will work, just know it's not ideologically the most elegant solution.
# Main site proxy
<VirtualHost *:80>
ServerAlias www.example.com
ServerName example.com
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://nodejsIP:8090/
ProxyPassReverse / http://nodejsIP:8090/
</VirtualHost>
# Subdomain proxies
<VirtualHost *:80>
ServerAlias www.api.example.com
ServerName api.example.com
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://nodejsIP:8090/api/
ProxyPassReverse / http://nodejsIP:8090/api/
</VirtualHost>
<VirtualHost *:80>
ServerAlias www.apps.example.com
ServerName apps.example.com
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://nodejsIP:8090/apps/
ProxyPassReverse / http://nodejsIP:8090/apps/
</VirtualHost>
Note: if your apache server and node server are both running off the same box and hence have the same IP, use http://localhost for the nodejsIP

NodeJS with Apache and directory listing

I am trying to migrate my NodeJS app which works fine from a dedicated server running Nginx to another running Apache2.
Here is my Nginx configuration file
server {
listen 80;
server_name example.com;
root /home/user/myapp;
location / {
proxy_pass http://example.com:9000;
}
location /logs {
autoindex on;
}
}
and here is my Apache2 configuration file
<VirtualHost *:80>
DocumentRoot /home/user/myapp
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://example.com:9000/
ProxyPassReverse http://example.com:9000/
</Location>
<Directory /home/user/myapp/logs>
Options +Indexes
</Directory>
</VirtualHost>
The NodeJS app works on both http server but I am only able to get the listing directory http://example.com/logs with Nginx but not with Apache2 where NodeJS responds
Cannot GET /logs/
Is something missing in the Apache2 configuration file? Obviously every Apache2 mod are enabled proxy_http proxy and autoindex.
Adding ProxyPass /logs ! works!
<VirtualHost *:80>
DocumentRoot /home/user/myapp
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /logs !
<Location />
ProxyPass http://example.com:9000/
ProxyPassReverse http://example.com:9000/
</Location>
<Directory /home/user/myapp/logs>
Options +Indexes
</Directory>
</VirtualHost>

Exclude an alias from virtualhost proxypass

I've following virtual host configuration. The desired result is:
If someone requests http://test.myserver.com/myapp, apache serves
him from /var/www/myapp
And if http://test.myserver.com/ is
requested, apache redirects it to port 8069.
2nd is working but 1st is not. Can someone help please!
<VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
</VirtualHost>
This is how I was able to achive the desired outcome. Following is the working configuration where ProxyPassMatch ^/myapp ! did the trick and except the (server-address)/myapp, all the requests are being proxying to the other server which is open-erp running at port 8069:
<VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPassMatch ^/myapp !
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
Instead of using:ProxyPassMatch ^/myapp ! you could have simply added another ProxyPass directive before the one defining /, like this:
ProxyPass /myapp !
ProxyPass / http://localhost:8069/
Since ProxyPass respects precedence (the first match will be processed), it will correctly redirect to the directory instead of proxying.
in case you have a RewriteCond (which is very likely when you run a proxy) this one will make you happy as well!
<Location /.well-known/acme-challenge/>
RewriteEngine off
ProxyPass !
</Location>

Resources