HTTP Requests going to wrong VirtualHost apache2 - apache

Hoping someone can lend me a hand here as this has been bugging me for a few days now.
I have a apache config file, it does both standard HTTP server work as well as reverse proxy for pages within the network.
If i create a new DNS A record for the IP address of the apache server it will automatically send the request to the camera1.domainname.com virtual host and then forward me 192.168.2.160.
What i want it to to do is send it to the folder /var/www/bad_url.
Any suggestions here would be great as im pretty sure im going to start loosing hair.
NameVirtualHost *
ErrorLog ${APACHE_LOG_DIR}/error_baduri.log
CustomLog ${APACHE_LOG_DIR}/access_baduri.log combined
DocumentRoot /var/www/bad_url
ProxyPreserveHost On
ErrorLog ${APACHE_LOG_DIR}/error_cam1.log
CustomLog ${APACHE_LOG_DIR}/access_cam1.log combined
LogLevel debug
ProxyPass / http://192.168.2.160/
ProxyPassReverse / http://192.168.2.160/
ServerAlias camera1.domainname.com
ProxyPreserveHost On
ErrorLog ${APACHE_LOG_DIR}/error_mediaserver.log
CustomLog ${APACHE_LOG_DIR}/access_mediaserver.log combined
LogLevel debug
ProxyPass / http://192.168.2.207/
ProxyPassReverse / http://192.168.2.207/
ServerAlias mediaserver.domainname.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerAlias ubuntu1 ubuntu1.domainname.com 192.168.2.208
DocumentRoot /var/www/html
All the above is in file 'etc/apache2/sites-enabled/default.conf'. There are no other config files in that folder.
Im running Ubuntu

Just quickly. it seems order matters. As long as i have the wild card up the top it went there first unless another virtual host matched the criteria. weird.

Related

Apache Reverse proxy is throwing 404 error

I am using apache2 for my reverse proxy but it keeps on throwing 404 for my setup
<VirtualHost *:80>
ServerAdmin admin#domain.com
ServerName domain.com
ServerAlias www.domain.com
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:7201/
ProxyPassReverse / http://localhost:7201/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Please do lemme know if there is something I can fix it in my setup. Thanks :)
Please change the port.
go to apache server.
config
httpd.conf
find and replace
80 and 8080 or 90 enter code here's you want

Domains crossed over on digital ocean

I have two domains. exampleone.com and exampletwo.com.
I followed this guide for adding multiple domains on the same server:
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
They are both on the same server. Somehow, blog.exampleone.com was created (out of nowhere). and it points to exampletwo.com.
If I click on the site in google, it shows blog.exampleone.com as the domain, but shows the content for exampletwo.com
How is this happening?
I've looked into the vhost files and everything seems correct.
Here is a sample vhost file:
<VirtualHost *:80>
ServerAdmin dave#example.com
DocumentRoot /var/www/html/exampleone.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.lognano
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This should result in 2 separate sites on the same server. Instead, a blog subdomain was created on one site that points to the content on another site.
What should I do?
Thanks!
You neeed to specify the "ServerName" in your vhost file, something like :
<VirtualHost *:80>
ServerAdmin dave#example.com
ServerName blog.exampleone.com
DocumentRoot /var/www/html/exampleone.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.lognano
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
in fact, for each vhost file, you need to specify the ServerName to work properly with your subdomains!

Apache as reverse proxy doesn't work

I am trying to publish, behind a proxy, a Spring app (also with Spring Security) which has /x/services as entry point. It is running in Tomcat in 8080 in Google Engine (Debian). I configure Apache 2 as a reverse proxy with next configuration
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ProxyRequests off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
# Servers to proxy the connection, or
# List of application servers Usage
ProxyPass / http://127.0.0.1:8080/x/services/
ProxyPassReverse / http://127.0.0.1:8080/x/services
ServerName localizator.org
ServerAlias *.localizator.org
</VirtualHost>
I checked it against a lot of examples and seems it is OK, but the only response I am getting is the "Index of /" page. And Apache logs are not helping at all.
Any help will be very appreciated.
For those with a similar problem don't forget to do :
sudo a2ensite proxy-host
(lets suppose your .conf file name is proxy-host)

Apache: Rewrite then Proxy

So, I have two servers, let's call them nice#server and a#another#server
nice#server is what clients will talk to and is running Apache2 performing basic reverse proxy for simple services, a#another#server hosts a proprietary application server on port . I need to completely rewrite two url's before they get passed through, but just add a folder to all other URLs.
Some Examples below:
User Requests: nice#server/
Apache requests a#another#server:8080/appname
User Requests: nice#server/css#css
Apache requests a#another#server:8080/appname/css#css
User Requests: nice#server/a
Apache requests a#another#server:8080/appname/command1?name=option1
User Requests: nice#server/b
Apache requests a#another#server:8080/appname/app2?name=option2
I have done a lot of Googling and test on this but cannot seem to get it to work, sorry I've not kept the links that i've tried!!! I have stripped the vHost file right back down for now.
<VirtualHost *:80>
ServerName service#domain#com
ErrorLog ${APACHE_LOG_DIR}/service-domain-com-error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/service-domain-com-access.log combined
ProxyPreserveHost On
ProxyRequests off
ProxyPass / a#another#server:8080/
ProxyPassReverse / a#another#server:8080/
</VirtualHost>
Thanks in advance for any guidance on how to do this.
I managed to get this fixed with a bit of trial and error. posting solution here in case anyone else is having the issue.
Working configuration file
<VirtualHost *:80>
ServerName service.domain.com
ErrorLog ${APACHE_LOG_DIR}/internal-fqdn-error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/internal-fqdn-access.log combined
RewriteEngine On
RewriteRule ^/a$ /appname/command1?name=option1 [PT]
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://a.another.server:8080/
ProxyPassReverse / http://a.another.server:8080/
</VirtualHost>

Looking to redirect path /blog to another server using Apache

I want to host my blog on it's own server, but have the URL be at mysite.com/blog
Should I do this using mod_proxy or an apache redirect, and how would I set this up on apache?
My first pass attempt looks like so in the vhost file, but failed:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /blog http://blog.server's.ip.address/
ProxyPassReverse /blog http://blog.server's.ip.address/
ServerAdmin me#myemail.com
ServerName mysite.com
DocumentRoot /var/www
<Directory /var/www>
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
With this is place I get the following error when restarting apache:
Restarting web server apache2 /sbin/start-stop-daemon: warning: failed to kill 11306: Operation not permitted
[fail]
The apache2 configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!
mod_proxy needs to be enabled before working >_<
Once I enabled it my config worked as expected.
a2enmod proxy_http
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /blog http://server4.hostinger.co.uk.ip.31.170.164.19/
ProxyPassReverse /blog http://server4.hostinger.co.uk.ip.31.170.164.19/
ServerAdmin http://webmail.hostinger.co.uk
ServerName armukul.com.ip address 31.170.164.123 domain ip ("A" DNS record) to this IP: 31.170.164.123
DocumentRoot /var/www.armukul.com/home/u311366417
<Directory /var/www>armukul.com
Order allow,deny
allow from all
</Directory>www>armukul.net
</Directory>www>facebook.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>[][1]
[1]: http://armukul.com/home