How to catch random wild subdomain/domain not register in the vhost - apache

Currently I'm stopping user direct access to my server via IP with the following conf
<VirtualHost *:80>
ServerName 123.123.123.123
Redirect permanent / https://google.com
UseCanonicalName Off
</VirtualHost>
However, I do setting *.abc.com to my server 123.123.123.123
How can i do the same, redirect those domains are not registered in my vhost serverName?

Related

Use Apache To Run SSL On Port 8980 Specifically

I have a web service which I access by typing the following URL exactly as is (character for character):
http://10.115.252.127:8980/opennms/login.jsp
The website files are served from /opt/opennms/jetty-webapps/opennms/
My objective is to use Apache (httpd.conf) to force any traffic to this URL to use SSL and no longer HTTP.
I have successfully installed the SSL certificates with no issues.
I have configured a VirtualHost directive to redirect port 80 to 443
Only sites under /var/www/html/* are being successfully redirected.
Example: http://10.115.252.127/numbers successfully redirects to https://10.115.252.127/numbers
http://10.115.252.127/charts successfully redirects to https://10.115.252.127/charts
But, when I type in the URL http://10.115.252.127:8980/opennms/login.jsp it is always served as HTTP...how do I make it served as HTTPS like the others? I have checked the forums and all the posts assume you will always be redirecting port 80 and dont say anything about how to use SSL in the scenario I explained. I have the same issue with another service running on port 3000 http://10.115.252.127:3000/login
===extract from my httpd.conf===
<VirtualHost *:80>
ServerName 10.115.252.127
Redirect permanent / https://10.115.252.127/
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/httpd/conf/ssl.crt/cert_mtocb2500lbscorp.crt
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/mtocb2500-lbscorp.key
ServerName 10.115.252.127
#Documentroot /var/www/html
</VirtualHost>
Based on your confirmation of my understanding, here is what you can do:
############################################################################
Listen 80
# All connections on port 80 are redirected to port 443
<VirtualHost *:80>
ServerName www.example.com
CustomLog "logs/80_access.log" combined
ErrorLog "logs/80_error.log"
Redirect permanent / https://www.example.com
# No documentRoot, no content
</VirtualHost>
############################################################################
Listen 443
# All URI are answered from the documentRoot directory
# EXCEPT /openms, which is proxied to :8980
<VirtualHost *:443>
ServerName www.example.com
# temporary, remove when tests done
LogLevel debug
CustomLog "logs/443_access.log" combined
Errorlog "logs/443_error.log"
SSLEngine on
SSLCertificateFile /etc/httpd/conf/ssl.crt/cert_mtocb2500lbscorp.crt
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/mtocb2500-lbscorp.key
# For your redirection to 8980
ProxyPass /opennms "https://www.example.com:8980/"
ProxyPassReverse /opennms "https://www.example.com:8980/"
documentRoot "/yourdir/apache/htdocs"
DirectoryIndex index.html
</VirtualHost>
Prerequisites
you must load proxy modules
you must load rewrite module
port 8980 is linked to some other software. Apache does not handle 8980.

Apache : Restrict acces to webserver via IP (HTTP/HTTPS)

I run a website on a VPS and I would like to completely block access to the website via The VPS IP Address.
I made it work for HTTP but It seems impossible for HTTPS.
What I did:
<VirtualHost *:80>
ServerName xxx.xxx.xxx.xxx
Redirect 403 /
DocumentRoot /a/folder/here/
</VirtualHost>
This worked perfectly as expected for http://xx.xx.xx.xx
But I could not find a way to do the same for https://xx.xx.xx.xx
Anyone can help me please?
** I am using:**
Letsencrypt Certificat
Apache 2.4
NOTE: the file containing this rule must be executed after other sites that use SSL.
ecample:
0-site1.conf = website using no ssl (port 80)
0-site1-ssl.conf = website using ssl (port 443)
1-direct-access-conf = the file containing:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName xxx.xxx.xxx.xxx
Redirect 403 /
DocumentRoot /a/folder/here/
</VirtualHost>
</IfModule>
Just do the same for the virtual host that is bonded to port 443:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName xxx.xxx.xxx.xxx
Redirect 403 /
DocumentRoot /a/folder/here/
</VirtualHost>
</IfModule>

IP and Wildcard VirtualHost Conflict

I'm trying to setup an Apache web server that has a couple WordPress Multisite installations. My goal is to have clients point their domain at one of the IP addresses say 209.50.xxx.xxx and that traffic gets directed to the WP Multisite directory. I also have other domains that need to go to a specific directory regardless of what their IP address is. I can't seem to get both IP Based and Wildcard VirtualHosts working together. I can only get one or the other. In the current setup below, I can get traffic on any domain pointed at 209.50.xxx.xxx to go to the correct directory, but app.example.com and www.example.com will just get an error "ERR_TOO_MANY_REDIRECTS".
## All Traffic to IP: 209.50.xxx.xxx on Port 80 (Catch All) ##
<VirtualHost 209.50.xxx.xxx:80>
DocumentRoot /var/www/example/site/public
</VirtualHost>
## All Traffic to IP 209.50.xxx.xxx on Port 80 with Domain app.example.com ##
<VirtualHost 209.50.xxx.xxx:80>
ServerName app.example.com
DocumentRoot /var/www/example/app/public
</VirtualHost>
## All Traffic to any IP on Port 80 with Domain www.example.com or example.com ##
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/example/main/public
</VirtualHost>
## All Traffic to any IP on Port 80 with Domain www.other-example.com or other-example.com ##
<VirtualHost *:80>
ServerName www.other-example.com
ServerAlias other-example.com
DocumentRoot /var/www/other-example/main/public
</VirtualHost>
I have tried different ordering with the current virtualhost catchall at the beginning flipped to the end with the same results.
Any ideas on how to fix this?
I setup a virtualbox with 2 IP addresses so that I could carefully test different virtual host configurations, and I believe that I have the solution. It seems that if I start using IP addresses in the VirtualHost line (<VirtualHost 192.168.1.201:80> instead of <VirtualHost *:80>) then I need to do that for every VirtualHost block. Then for the "Catch-All" blocks for each IP, I keep that first at the top of the file (The order is important.)

How to deny https requests to my servers public ip address

I have a server running Apache 2 that has 6 virtual hosts. All the virtual hosts run over SSL. However if you make a request to my server's IP (for example: https://11.22.33.444) since there is no certificate for my IP you are redirected to the last virtual host alphabetically and whatever app is linked to that virtual host will load over https://11.22.33.444.
My question is how can I either
redirect any traffic loading over my server's public IP address to an error page
OR
Deny any traffic loading over my server's public IP address and shutdown the connection
Apache prioritizes VirtualHosts in terms of order. By putting a very basic server at the top, it will redirect all traffic (that doesn't satisfy the other virtual hosts) to that webpage.
#default server b/c first
<VirtualHost *:80>
Redirect 302 / https://www.mainsite.com/error_page
</VirtualHost>
#main server
<VirtualHost *:443>
ServerName www.mainsite.com
DocumentRoot ...
SSLEngine on
SSLCertificateFile.....etc.
</VirtualHost>
<VirtualHost *:443>
ServerName www.secondsite.com
DocumentRoot ...
SSLEngine on
SSLCertificateFile.....etc.
</VirtualHost>
#force https servers
<VirtualHost *:80>
ServerName www.mainsite.com
Redirect 301 / https://www.mainsite.com/
</VirtualHost>
<VirtualHost *:80>
ServerName portfolio.secondsite.com
Redirect 301 / https://www.secondsite.com/
</VirtualHost>

Apache VirtualHost is not working

I have a server running Apache 2.4 on Windows, and I have set up a VirtualHost in the httpd-vhosts.conf file, and an 'A' record in my DNS server that points subdomain.mydomain.com to my IP address. Unfortunately, connecting to subdomain.mydomain.com just shows the same page as mydomain.com. Here is the code I used in the httpd-vhosts.conf file:
<VirtualHost *:80>
ServerAdmin admin#mydomain.com
DocumentRoot "c:/Apache24/subdomain/htdocs"
ServerName subdomain.mydomain.com
ErrorLog "c:/Apache24/subdomain/logs/errors.log"
CustomLog "c:/Apache24/subdomain/logs/access.log"
</VirtualHost>
What am I doing wrong?
Make sure your domain provider configuration doesn't redirect # to www, you need them to be configured separately to redirect to your machines IP address