Apache2 Proxy Websocket connections - node.js

i followed many tutorials on how to add reverse proxy on Nodejs applications, i installed one on my VPS that uses websocket, this is my apache2 config.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName tracker.local.dev
ServerAdmin webmaster#localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://127.0.0.1:8085/
ProxyPassReverse / http://127.0.0.1:8085/
SSLProxyEngine On
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/tracker.local.dev/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/tracker.local.dev/privkey.pem
</VirtualHost>
# vim: syntax=apache ts=4</VirtualHost>
</IfModule>
I can connect to the NodeJS App but it won't connect the Websocket, i already enabled every module and checked everything on my config, but i can't make it work.

Related

Enable Cookies for reverse Proxy and Apache2

i try to access an application on a tomcat server via a reverse proxy and apache2.
The reverse proxy is working just fine, but the application throws an error, that cookies are disabled.
I googled but nothing helped.
My vhost.conf file:
<VirtualHost *:80>
ServerName testcms.mydomain.de
ServerAdmin webmaster#localhost
DocumentRoot /var/www/cms
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/opencms/
ProxyPassReverse / http://127.0.0.1:8080/opencms/
ProxyPassReverseCookieDomain http://localhost:8080/opencms testcms.mydomain.de
ProxyPassReverseCookiePath / /cms/Cookies
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =testcms.mydomain.de
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName testcms.mydomain.de
ServerAdmin webmaster#localhost
DocumentRoot /var/www/cms
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/opencms/
ProxyPassReverse / http://127.0.0.1:8080/opencms/
ProxyPassReverseCookieDomain 127.0.0.1:8080/opencms/ testcms.mydomain.de
ProxyPassReverseCookiePath / /cms/cookies
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/testcms.mydomain.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/testcms.mydomain.de/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
The ProxyPassReverseCookieDomain and ProxyPassReverseCookiePath should help, but they dont.
Did I miss something while implementing the reverse proxy?
Thanks for the help!

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/

Apache ProxyPass not loading Resources

I configured apache proxypass and it's working but not loading images, javascript, CSS etc... I want to proxypass to another server, not localhost. Below is my configuration.
see error image
<VirtualHost *:80>
ServerName app.server.com
DocumentRoot /var/www/html/subdomain
RewriteEngine on
ProxyRequests Off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass /apm http://192.168.1.102:9999/
ProxyPassReverse /apm http://192.168.1.102:9999/
</virtualHost>
After some research and reading some tutorials I got a solution.
<VirtualHost *:80>
ServerName app.server.com
DocumentRoot /var/www/html/subdomain
RewriteEngine on
ProxyRequests Off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass / http://192.168.1.102:9999/
ProxyPassReverse / http://192.168.1.102:9999/
</VirtualHost>

Proxypass nodejs app on subdomain with Apache 2.4.29

The app I'm using is Lolisafe and it opens a local port to 9999.
For my domain, I need the regular website to work (https://example.com) but also have a subdomain (https://sub.example.com) to link to the nodejs application which has a home.html page under /srv/http/lolisafe/pages/. Lolisafe also uses an API which calls under /api, so for example https://sub.example.com/api is how logging in functions.
All my domains files reside in /srv/http
httpd.conf:
Include conf/extra/site/domain.conf
Include conf/extra/site/lolisafe.conf
A Records are set for #, www, and lolisafe all with the same IP.
Currently my /etc/httpd/conf/extra/site/domain.conf file contains this:
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot "/srv/http/"
ServerName example.com
ServerAlias www.example.com
ErrorLog "/var/log/httpd/example.com-error_log"
CustomLog "/var/log/httpd/example.com-access_log" common
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin#example.com
DocumentRoot "/srv/http/"
ServerName domain.com
ServerAlias www.domain.com
ErrorLog "/var/log/httpd/example.com-error_log"
CustomLog "/var/log/httpd/example.com-access_log" common
SSLEngine on
SSLCACertificateFile /etc/httpd/conf/ca_bundle.crt
SSLCertificateFile /etc/httpd/conf/server.crt
SSLCertificateKeyFile /etc/httpd/conf/server.key
</VirtualHost>
And /etc/httpd/conf/extra/site/lolisafe.conf contains:
<VirtualHost *:*>
ProxyPreserveHost On
ServerName lolisafe.example.com
DocumentRoot "/srv/http/lolisafe/pages/"
ProxyPass "/" "http://0.0.0.0:9999/"
ProxyPassReverse "/" "http://0.0.0.0:9999/"
</VirtualHost>
Currently with this setup, visiting https://sub.example.com goes directly to https://example.com. What am I doing wrong?

Resources