Issue with loadbalancing on apache - linux

Please help with my task.
I'm must to install apache which will be balance connections by nodes (P.S. there is JIRA app nodes, if this is important).
I find how to do this, and once i have do this, and all works correctly. But in this time i put the same part of code in the httpd.conf
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
NameVirtualHost *:443
<VirtualHost *:443>
ProxyRequests off
ServerName jira-host
SSLEngine on
SSLCertificateFile "/etc/httpd/certs/jira-host.crt"
SSLCertificateKeyFile "/etc/httpd/certs/jira-host.key"
ProxyTimeout 900
Timeout 900
SSLSessionCacheTimeout 1800
<Proxy balancer://jiracluster>
BalancerMember http://jira-host1:8080 route=node1
BalancerMember http://jira-host2:8080 route=node2
Order Deny,Allow
Deny from none
Allow from all
ProxySet stickysession=ROUTEID
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
Order deny,allow
Allow from all
</Location>
ProxyPass /balancer-manager !
ProxyPass / balancer://jiracluster/
ProxyPreserveHost on
</VirtualHost>
<VirtualHost *:80>
ServerName jira-host
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://jira-host [R,L]
</VirtualHost>
And after restart apache get the standart apache hello page, instead balancing.
What i do wrong? please help.
Thx.

Please ensure that you check all your configuration files.
It would seem that another file is still routing traffic to the default apache file.
Please check all your port 80/443 config files.

Related

Getting 404 on a specific path /pricing with Apache server [migrated]

This question was migrated from Stack Overflow because it can be answered on Server Fault.
Migrated 2 days ago.
I've set up an Apache server on Ubuntu 20.04
The site loads fine when I load the home page first (https://leadzilla.ai) and after that when I click on the pricing button and it takes me to https://leadzilla.ai/pricing and the that page loads fine as well.
But when I go directly to https://leadzilla.ai/pricing in the browser, I get a 404
Here is what I have in /etc/apache2/sites-available/leadzilla.ai.conf
<VirtualHost *:80>
DocumentRoot /var/www/leadzilla.ai
ServerName leadzilla.ai
ServerAlias www.leadzilla.ai
<Directory /var/www/leadzilla.ai>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =leadzilla.ai [OR]
RewriteCond %{SERVER_NAME} =www.leadzilla.ai
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I have this config in /etc/apache2/sites-available/leadzilla.ai-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /var/www/leadzilla.ai
ServerName leadzilla.ai
ServerAlias www.leadzilla.ai
<Directory /var/www/leadzilla.ai>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Allow from all
#Deny from all
#Allow from 127.0.0.1
#Allow from ::1
</Directory>
<Directory /var/www/leadzilla.ai/blog>
AllowOverride All
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/leadzilla.ai/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/leadzilla.ai/privkey.pem
</VirtualHost>
</IfModule>
I have Wordpress on https://leadzilla.ai/blog so that has to be taken care of as well.
Here is what I have tried:
RewriteRule ^pricing$ pricing.html [NC]
I added it before the other rewrite rule but that doesn't seem to be working. Any ideas?
[EDIT]
This is solved now. The issue was a Next.js config, not an Apache config.
I put in exportTrailingSlash: true in my module.exports and it worked
I find this to be curious behavior. But if you have a RewriteRule in the <VirtualHost *:443>, then you should also have RewriteEngine On.
Are there any symbolic links in your directory at all. Anything like foo -> foo.html?
Are there any directories like /var/www/html/pricing/ in your directory structure?
Also, remember, that all of your traffic ends up on HTTPS, which means that only the <VirtualHost *:443> is in play. The other virtual host entry only is used long enough to redirect from HTTP to HTTPS. Any rewrite rules for the :80 VirtualHost do not apply on HTTPS.

Proxyreverse in Apache2 with wordpress

I have installed and configured Wordpress on my server using also apach2 virtualhosts.
I made a virtualhost with this config
<VirtualHost *:80 *:443>
ServerAdmin yourluxuryroad#gmail.com
ServerName yourluxuryroad.com
ServerAlias www.yourluxuryroad.com
DocumentRoot /var/www/yourluxuryroad
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.yourluxuryroad.com [OR]
RewriteCond %{SERVER_NAME} =yourluxuryroad.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /node-yrl-book http://localhost:5000
ProxyPassReverse /node-yrl-book http://localhost:5000
</VirtualHost>
<Directory /var/www/yourluxuryroad/>
AllowOverride All
</Directory>
As you can see from the config i'm trying to set the ProxyPass directive for redirect the requests recived on the path /node-yrl-book to a nodejs service ( made using expressjs ) at port 5000 but this is not working, instead of getting a redirect to that service i get the 404 Page not found wordpress page.
If I make a request at my_ip/node-yrl-book instead it works correctly and i am redirected to the service at port :5000
I suppose that i'm missing something in my configuration but i'm not understanding what..
Maybe is something in wordpress that has to be changed?
You have way too much going on.
ProxyPass -or- DocumentRoot, not both.
You can either serve the page from apache (by using DocumentRoot), or you can serve the page from nodejs (by using ProxyPass).
Finally i solved this, I made an SSL certificate for my website using let's encrypt certbot, This script created a new virtualhost in another file for the https requests ( called /etc/apache2/sites-available/myDomain-le-ssl.conf ) That virtualhost was overriding my proxypass directive, editing also this virtualhost made all work

You configured HTTPS(443) on the standard HTTP(80) port

In my apache error logs, I have bunch of ssl warnings saving You configured HTTPS(443) on the standard HTTP(80) port!
Here is my site.ca.conf file
<VirtualHost *:80>
ServerName site.ca:80
DocumentRoot "/var/www/site/public"
<Directory "/var/www/site/public">
AllowOverride all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =site.ca
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
and here is my site.ca-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName site.ca:80
DocumentRoot "/var/www/site/public"
<Directory "/var/www/site/public">
AllowOverride all
</Directory>
ServerAlias site.ca
SSLCertificateFile /etc/letsencrypt/live/site.ca/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site.ca/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Every thing works fine. I am not sure why this warning shows up every day in my apache log files, and how can I resolve it?
Generally, this is because you do not have any SSL configuration on the virtual host on port 443. You may need to enable "SSLEngine on" and provide certificate information. The warning indicates are serving regular HTTP traffic on what is usually an HTTPS port.
In these config files listed by the requester, there are some tweaks/corrections to be done:
we don't need to have a DocumentRoot in the site.ca.conf because we will redirect HTTP to the HTTPS (site.ca-le-ssl.conf)
the ServerName directive shouldn't have a port number, instead it should be in the VirtualHost level
the ServerName and ServerAlias should be near to each other and there should be www.site.ca as an Alias too in both files to handle the requests containing the www
in site.ca-le-ssl.conf file there is a ServerName site.ca:80 and that's not correct (there should be no port number)
there must be a SSLEngine on in the site.ca-le-ssl.conf
I hope that help someone even this is an old question

How to configure subdomains in bitnami ruby stack

I am using Bitnami ruby stack on Google Cloud which supports php and nodejs at the same time. I have want my express js app which I want to run on main domain. eg www.example.com and I have two other codeigniter app (PHP) which I want them to run on subdomains like one.example.com and the other on domain like two.example.com.
I have followed different Bitnami articles such these 1 2 3 but still I can't have both apps run well together.
I placed all apps inside /opt/bitnami/apps and every app folder has 2 sub folders which are conf and htdocs just as described in article.
Here are contents of conf folder of codeigniter app which I want it to run on subdomain.
/opt/bitnami/apps/one/conf/httpd-app.conf
<Directory /opt/bitnami/apps/one/htdocs/>
Options +FollowSymLinks
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Directory>
/opt/bitnami/apps/one/conf/httpd-vhosts.conf
<VirtualHost *:8080>
ServerName one.example.com
ServerAlias www.one.example.com
DocumentRoot "/opt/bitnami/apps/one/htdocs"
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1$1 [R=permanent,L]
Include "/opt/bitnami/apps/one/conf/httpd-app.conf"
</VirtualHost>
<VirtualHost *:8444>
ServerName one.example.com
ServerAlias www.one.example.com
DocumentRoot "/opt/bitnami/apps/one/htdocs"
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1$1 [R=permanent,L]
Include "/opt/bitnami/apps/one/conf/httpd-app.conf"
</VirtualHost>
And conf of nodejs app which I want to run on main domain.
/opt/bitnami/apps/main/conf/httpd-app.conf
ProxyPass / http://127.0.0.1:2000/
ProxyPassReverse / http://127.0.0.1:2000/
/opt/bitnami/apps/nyererefy/conf/httpd-vhosts.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
# redirect www and non-www http routes to https-non-www:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
Include "/opt/bitnami/apps/main/conf/httpd-app.conf"
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
#redirect https-wwww to https-non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
Include "/opt/bitnami/apps/main/conf/httpd-app.conf"
</VirtualHost>
/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf
# Bitnami applications installed in a prefix URL
Include "/opt/bitnami/apps/phpmyadmin/conf/httpd-prefix.conf"
Include "/opt/bitnami/apps/phppgadmin/conf/httpd-prefix.conf"
Include "/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf"
/opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf
# Bitnami applications installed in a Virtual Host
Include "/opt/bitnami/apps/one/conf/httpd-vhosts.conf"
Include "/opt/bitnami/apps/main/conf/httpd-vhosts.conf"
/opt/bitnami/apache2/conf/bitnami/bitnami.conf
# Default Virtual Host configuration.
<IfVersion < 2.3 >
NameVirtualHost *:80
NameVirtualHost *:443
</IfVersion>
<VirtualHost _default_:80>
DocumentRoot "/opt/bitnami/apache2/htdocs"
<Directory "/opt/bitnami/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3 >
Require all granted
</IfVersion>
</Directory>
# Error Documents
ErrorDocument 503 /503.html
# Bitnami applications installed with a prefix URL (default)
Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
</VirtualHost>
# Default SSL Virtual Host configuration.
<IfModule !ssl_module>
LoadModule ssl_module modules/mod_ssl.so
</IfModule>
Listen 443
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !EDH !RC4"
SSLPassPhraseDialog builtin
SSLSessionCache "shmcb:/opt/bitnami/apache2/logs/ssl_scache(512000)"
SSLSessionCacheTimeout 300
<VirtualHost _default_:443>
DocumentRoot "/opt/bitnami/apache2/htdocs"
SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/server.key"
<Directory "/opt/bitnami/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3 >
Require all granted
</IfVersion>
</Directory>
# Error Documents
ErrorDocument 503 /503.html
# Bitnami applications installed with a prefix URL (default)
Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
</VirtualHost>
# Bitnami applications that uses virtual host configuration
Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf"
# Status
ExtendedStatus on
<VirtualHost _default_:80>
ServerName local-stackdriver-agent.stackdriver.com
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>
How to configure them to run together?
Bitnami developer here!
You need to configure all your applications to use Apache virtual hosts.
First, you need to change the default root application to be configured with virtual host instead of using the Apache prefix.
This is done through the files /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf and /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf.
Second, you need to configure your codeigniter applications as virtual hosts too. This guide may be helpful.
https://docs.bitnami.com/general/infrastructure/lapp/configuration/configure-custom-application/
Also, if you have any issues feel free to open a case in the Bitnami community forum.

Apache and Node on same IP

I have a single VPS with one IP. I'm using Apache to serve cloud.mysite.com and I have a NodeJS application listening on port 3000.
I'm trying to configure my VPS in a way so that when I visit mysite.com, I get my NodeJS application.
Instead, when I visit mysite.com, I'm forwarded to cloud.mysite.com.
My .conf files are below.
mysite.com.conf
<VirtualHost mysite.com:80>
ServerName mysite.com
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
cloud.mysite.com
<VirtualHost cloud.mysite.com:80>
ServerName cloud.mysite.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =cloud.mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
<VirtualHost cloud.mysite.com:443>
# Basics
ServerName www.cloud.mysite.com
ServerAlias www.cloud.mysite.com
# Next line puts ownCloud at the domain root instead of a /owncloud/ subdirectory (e.g. example.com vs. example.com/owncloud/)
Alias /owncloud "/var/www/owncloud/"
DocumentRoot /var/www/owncloud
# SSTL STUFF GOES HERE
# ownCloud
<Directory /var/www/owncloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/owncloud
SetEnv HTTP_HOME /var/www/owncloud
</Directory>
</VirtualHost>
SSLStaplingCache shmcb:/var/run/ocsp(128000)
Edit: I resolved this by clearing my cache.
It seems that it should proxy requests to your Node app if it's running on and listening on port 3000 on the same host, or fail if it isn't - but not to proxy requests to the other virtual host.
Make sure that you restarted Apache or made it reload the configuration after you made those changes and that your new config file is where it should be and is enabled.

Resources