Proxypass nodejs app on subdomain with Apache 2.4.29 - node.js

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?

Related

Apache listen all domains

My web project need new mirrors domain each weeks.
The website is able to buy himself the domain with a Registar API.
I'm wundering if there is a way to automatically add the new domain to the virtualhost or config the virtualhost to redirect every domains not present in the virtualhost to a specific DocumentRoot ?
If I do that it will work ?
<VirtualHost *:80>
ServerName mirror.com
ServerAlias *.mirror.com
DocumentRoot /var/www/public
</VirtualHost>
<VirtualHost *:80>
ServerName *
DocumentRoot /var/www/public
</VirtualHost>
I fixed the issue with this :
<VirtualHost *:80>
ServerName mirror.com
ServerAlias *
DocumentRoot /var/www/public
</VirtualHost>

Apache virtualhost configuration

I am tring to set two virtual host (example.com.conf and test.com.conf):
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
and
<VirtualHost *:80>
ServerAdmin admin#test.com
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/test.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
The problem is that if I go on localhost in my browser it is shown the website www.example.com. If I type localhost/test.com there is error not found. My goal should be to address both website with localhost/example.com and localhost/test.com.
Sounds like you could use the ServerPath directive for apache, in your case something like this should work:
<VirtualHost 127.0.0.1>
# primary vhost
DocumentRoot "/var/www/example.com"
RewriteEngine On
RewriteRule "." "/var/www/example.com/public_html"
# ...
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "/var/www/example.com/public_html"
ServerName localhost
ServerPath "/example/"
RewriteEngine On
RewriteRule "^(/sub1/.*)" "/var/www/example$1"
# ...
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "/var/www/test.com/public_html"
ServerName localhost
ServerPath "/test/"
RewriteEngine On
RewriteRule "^(/sub2/.*)" "/var/www/test$1"
# ...
</VirtualHost>
The first Vhost would be so that localhost defaults to example.com page.
if you want to browse to these folders under any virtual host, like http://localhost/test.com, then you simply need an alias directive inside a location tag appended to the end of any active virtual host
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Location "/example.com">
Alias "/var/www/example.com/public_html"
</Location>
<Location "/test.com">
Alias "/var/www/test.com/public_html"
</Location>
Or you can put it inside the virtual host if you don't want it available anywhere else
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Location "/example.com">
Alias "/var/www/example.com/public_html"
</Location>
<Location "/test.com">
Alias "/var/www/test.com/public_html"
</Location>
</VirtualHost>

wrong vhost configuration in /etc/httpd/conf.d/vhost.conf

My vhost configuration at /etc/httpd/conf.d/vhost.conf looks like this:
NameVirtualHost *
<VirtualHost *>
ServerName www.example.com
DocumentRoot /var/www/html/site
</VirtualHost>
<VirtualHost *>
ServerName en.example.com
DocumentRoot /var/www/html/english
</VirtualHost>
<VirtualHost *>
ServerName photo.example.com
DocumentRoot /var/www/html/photo
</VirtualHost>
<VirtualHost *>
ServerName music.example.com
DocumentRoot /var/www/html/music
</VirtualHost>
<VirtualHost *>
ServerName video.example.com
DocumentRoot /var/www/html/video
</VirtualHost>
Now, only www.example.com is showing the correct site at /var/www/html/site. All other subdomains are giving a 500 internal server error. What am i doing wrong?
UPDATE:
i am really sorry guys... my Domain Name guy confirmed to me that my domain names were routed correctly to my IP address.... only after i did a dig en.example.com (something i should have done a lot earlier) did i realize that my Domain Name guys made a stupid misconfiguration... the web addresses were not even reaching my IP address to begin with... really sorry for the trouble folks :( :( - this vhost.conf file is all right
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html/site
</VirtualHost>
<VirtualHost *:80>
ServerName en.example.com
DocumentRoot /var/www/html/english
</VirtualHost>
<VirtualHost *:80>
ServerName photo.example.com
DocumentRoot /var/www/html/photo
</VirtualHost>
<VirtualHost *:80>
ServerName music.example.com
DocumentRoot /var/www/html/music
</VirtualHost>
<VirtualHost *:80>
ServerName video.example.com
DocumentRoot /var/www/html/video
</VirtualHost>

VirtualHost configuration overwriten the main domain

I configure apache to the main domain in my server and it works just fine if just that domain:
in httpd.conf:
Listen maindomain.com:80
DocumentRoot "/home/webserver/maindomain/html"
but add a VirtualHost like this :
<VirtualHost secondoDomain.com>
DocumentRoot /home/webserver/secondoDomain/html/
ServerName secondoDomain.com
ErrorLog /home/webserver/secondoDomain/logs/error_log
CustomLog /home/webserver/secondoDomain/logs/access_log common
</VirtualHost>
all the calls to http://maindomain.com are been redirected to secondoDomain.com.
Any of you knows why?
When you add a virtual host, you need an entry for the main domain as well - as all hosts become virtual.
For example:
Listen *:80
<VirtualHost *:80>
ServerName maindomain.com
ServerAlias localhost
DocumentRoot "/home/webserver/maindomain/html"
</VirtualHost>
<VirtualHost *:80>
ServerName seconddomain.com
DocumentRoot "/home/webserver/secondoDomain/html/"
</VirtualHost>
Make sure you have a <Directory "/home/webserver/secondoDomain/html/"> for that second folder as well.

How to fix this virtual host setup?

I have setup up 2 virtual hosts that share the same IP on a centos server running apache 2.
#<VirtualHost *:80>
# ServerAdmin webmaster#dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/a
ServerName www.a.com
ServerAlias a.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/b
ServerName www.b.com
ServerAlias b.com
</VirtualHost>
Regardless of what URL I point to. Site A shows up.
How can I fix? I should have a.com going to a and b.com going to b.
Thanks all
Is the following set in your httpd.conf?
NameVirtualHost *
An example from the documentation:
NameVirtualHost *
<VirtualHost *>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
make sure you have this directive as well
NameVirtualHost *
it could be displaying site A because it's set as the default document root. check your global settings, make sure the document root is not set to the same root as site A.
I have always declared the domain as the name.. never had issue.
NameVirtualHost localhost:80
<VirtualHost localhost:80>
DocumentRoot "/home/eddie/workspace/"
</VirtualHost>
<VirtualHost digbiz.localhost:80>
DocumentRoot "/home/eddie/workspace/Digital_Business/app/webroot"
</VirtualHost>
<VirtualHost wishlist.localhost:80>
DocumentRoot "/home/eddie/workspace/WishList/app/webroot"
</VirtualHost>
<VirtualHost phpmyadmin.localhost:80>
DocumentRoot "/srv/www/phpMyAdmin"
</VirtualHost>
<VirtualHost test.localhost:80>
DocumentRoot "/home/eddie/workspace/CakePHPTesting/app/webroot"
</VirtualHost>
<VirtualHost auth.localhost:80>
DocumentRoot "/home/eddie/workspace/EntMeetCapt/app/webroot"
</VirtualHost>

Resources