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>
Related
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?
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>
Is it possible to configure my URL which has my IP address on it- like: "http://192.168.xx.yy/index.php". The situation is when I run Apache server in my PC, and load localhost in it. I know it is possible after hosting with external server, but is there any way we can configure within our localhost?
How to configure the Apache files to make this happen? I tried in my localhost, editing the "httpd.conf" by adding this inside like this - please tell me where I am getting the issue!
ServerName localhost:80
HostnameLookups Off
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
ServerAlias example.com
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName other.example.com
DocumentRoot /www/otherdomain
</VirtualHost>
DocumentRoot "c:/wamp/www/"
Yes, you can play with multiple IP addresses on your machine. Configuration depends on your OS. Article Create Multiple IP Addresses to One Single Network Interface is for linux.
But, better way is to use VirtualHosts based on host names or (simplest) on ports. So you can get http://siteA.mycoputer.localhost, http://siteB.mycomputer.localhost in the first case and http://192.168.x.y:8000, http://192.168.x.y:9000 in the second case
Here is Apache Server config example from Apache Server 2.2 documentation
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org
# Other directives here
</VirtualHost>
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
I'm looking to set up VirtualHosts on my apache server and was looking for documentation that would tell me if these 2 entries are identical
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName example1.com
</VirtualHost>
Notice the lack of www. in the second one.
Thanks
This is from the Apache docs (http://httpd.apache.org/docs/2.0/mod/core.html#servername):
The ServerName directive sets the hostname and port that the server uses to identify itself. This is used when creating redirection URLs. For example, if the name of the machine hosting the web server is simple.example.com, but the machine also has the DNS alias www.example.com and you wish the web server to be so identified, the following directive should be used:
ServerName www.example.com:80
So I guess they are not identical.