Different site at HTTP vs HTTPS - apache

I am taking over a multi-site Apache server, with two websites (A and B). Going to website A's url via http works fine. Going to the same url, but using https, shows website B. Why is this, and how do I make https://urlA.com go to website A?

I solved the problem.
The servers were set up with VirtualHosts, but there was no VirtualHost for port 443. So it looked something like this:
<VirtualHost 99.9.9.999:80>
DocumentRoot /var/www/example
ServerName example.com
<Directory "/var/www/example">
Options Indexes
AllowOverride None
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
</Directory>
Adding a VirtualHost listening on port 443, with the SSLCertFiles specified fixed the problem.
<VirtualHost 99.9.9.999:443>
DocumentRoot /var/www/example
ServerName example.com
<Directory "/var/www/example">
Options Indexes
AllowOverride None
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
</Directory>
SSLCertificateFile /etc/httpd/conf/example.crt
SSLCertificateKeyFile /etc/httpd/conf/_.example.key
SSLCertificateChainFile /etc/httpd/conf/gd_example.crt
SSLEngine on
</VirtualHost>

Related

How apache2 can deny connections to a domain which is not hosted

I am hosting website iplocation.io on a cloud server. I found a domain https://chrissloey.com/index.php which opens my website within it.
Now from what I understand, chrissloey.com has pointed it A record to my server ip and my apache2 server is not denying connection to it and allow's to open iplocation.io website content like its own.
I want apache2 to deny connections to any other domain and only allow my own domain to server content.
Attached is apache conf file for iplocation.io
<VirtualHost *:80>
ServerAdmin email#email.com
DocumentRoot /var/www/public_html
ServerName iplocation.io
ServerAlias www.iplocation.io
ErrorLog ${APACHE_LOG_DIR}/apache-error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/public_html>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName iplocation.io
ServerAdmin email#email.com
DocumentRoot /var/www/public_html
SSLEngine on
SSLCertificateFile /path-to-csr
SSLCertificateKeyFile /path-to-key
SSLCertificateChainFile /path-to-ca
<Directory /var/www/public_html>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
</IfModule
Looking at the two comments I think the combination makes most sense:
Configure httpd to respond with redirect (301) to all incoming requests. This could be done on the 'root' host.
Configure a virtualhost listening to your domain only, and this one would serve your real content only.
This will work unless the other site requests your content and then integrates it into their responses. But as you said someone else simply put up a DNS A record.

Subdomain on WAMP Server Not Working

I'm having an important issue with my WAMP Server configuration. I've tried many configurations listed on many websites to no avail. I'm trying to make the directory /forums be accessible via https://forums.centmc.tk. However, upon travelling to https://forums.centmc.tk, it almost immediately says "forums.centmc.tk's server IP address could not be found." https://centmc.tk works fine, and so does the 301 redirect from https://centmc.tk/forums to https://forums.centmc.tk. I just can't figure out why the subdomain won't work.
I know it's an issue with my httpd-vhosts.conf file, so here's that:
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "c:/wamp64/www"
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot c:/wamp64/www
ServerName centmc.tk
SSLEngine on
SSLCertificateFile c:/wamp64/bin/apache/apache2.4.27/conf/centmc.tk.crt
SSLCertificateKeyFile c:/wamp64/bin/apache/apache2.4.27/conf/centmc.tk.key
Redirect 301 /forums https://forums.centmc.tk
Redirect 301 /forum https://forums.centmc.tk
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName centmc.tk
ServerAlias forums.centmc.tk
VirtualDocumentRoot "c:/wamp/www/forums"
ErrorLog "c:/wamp64/bin/apache/apache2.4.27/logs/errors.log"
<Directory "c:/wamp/www/forums">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Thanks for any help in advance! Sorry for the rather large text brick at the top.
Lucas.
Sounds like a DNS problem. If you are running a DNS server on your network, you will need to add an "A" record for the "forums" subdomain. Something like this:
; example.com [448369]
$TTL 86400
# IN SOA ns1.linode.com. admin.example.com. 2013062147 14400 14400 1209600 86400
# MX 10 mail.example.com.
# A ###.###.###.###
mail A ###.###.###.###
www A <put your server IP here>
forums A <put your forums server IP here>
If you're using public DNS servers (like 8.8.8.8, 4.4.4.4, or just your default ISP's DNS servers... you'll need to add a CNAME record to wherever your domain name is registered. (GoDaddy for example). Here's a link to how to do it on GoDaddy: https://www.godaddy.com/help/add-a-subdomain-that-points-to-an-ip-address-4080
I hope that helps.

Redirect in one virtual host file affecting all

I have a virtual host file with a redirect in it to force requests for the domain to https.
It seems to work too well. I added another virtual host file, and all requests for it (:80) are redirected to the first domain on :443. That is, requests for sub.b.com:80 get redirected to a.com:443. Note that b.com is not on the same server, only its sub domain is.
a.com
<VirtualHost a.com:80>
ServerName a.com
Redirect permanent / https://a.com/
</VirtualHost>
<VirtualHost a.com:443>
ServerName a.com
DocumentRoot /var/www/html/a
SSLEngine On
SSLCertificateFile /usr/local/share/ca-certificates/www.a.com.crt
SSLCertificateKeyFile /etc/ssl/private/a.com.key
<Directory /var/www/html/a>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
sub.b.com
<VirtualHost *:80>
ServerName sub.b.com
DocumentRoot /var/www/html/b
<Directory /var/www/html/b>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Requests for b.com will be handled by the first <VirtualHost> because you have no <VirtualHost> for b.com.
You only have a <VirtualHost> for sub.b.com.
So b.com is handled by the first <VirtualHost> for that IP/port, since none is assigned to handle it and that is the way it defaults.

Virtual host - Not Found

I wolud like to use virtual host on Apache 2.4
I use Xampp and I will have more site so on it.
I have already read some guide and I have edit my httpd.config
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
and the Load
also my defalut port in busy, so I have set
Listen 8080
After that I edit my httpd-vhosts.conf in this way
NameVirtualHost *:8080
<VirtualHost *:8080>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:8080>
ServerName sample.locl
DocumentRoot "C:\wwww\sample"
<Directory "C:\wwww\sample">
DirectoryIndex index.php
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8080>
ServerName sample2.locl
DocumentRoot "C:\wwww\sample2"
<Directory "C:\wwww\sample2">
DirectoryIndex index.php
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
N.B. my site is in C:/www/sample and c:/www/sample2 and my xampp in in c:/xampp.
At the end I edit my host in system32 with
127.0.0.1 localhost
127.0.0.1 sample
127.0.0.1 sample2
Now I have 404 error, neither when I wrote: "localhost" in my url browser.
If i Understand how it work I suppose that when i write localhost it will be redirect to C:\xampp\htdocs and so I should see my xampp page but it's not so.. where did I go wrong?
I always recive
Not Found
HTTP Error 404. The requested resource is not found.
thanks in advance

Why does port-based VirtualHost not work?

I'm trying to serve up two different Django apps on two separate ports. I have app1 on port 80 and app2 on port 8080. So what I'm expecting is that when I put example.com:80 into my browser, my request should get served up from app1, and when I put example.com:8080 into my browser, my request should get served up from app2. However, sometimes it will serve up my request from the wrong app. Then, after a few refreshes, it will sometimes switch. What's more, sometimes it will serve up from the correct app and then, after a few refreshes, switch to the wrong one. I know this isn't due to caching on the browser's end because I've also tried sending requests with curl from the machine and I get the same behavior. I can't understand why I'm getting this unexpected, nondeterministic behavior.
Here is my VirtualHost configuration:
<VirtualHost *:80>
ServerAlias *
ServerPath /app1/
WSGIScriptAlias /app1 /home/eyuelt/app1/app1/wsgi.py
Alias /app1/static /home/eyuelt/app1/staticfiles
<Directory /home/eyuelt/app1/app1>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
<Directory /home/eyuelt/app1/staticfiles>
AllowOverride None
Order Deny,Allow
Require all granted
</Directory>
</VirtualHost>
Listen 8080
<VirtualHost *:8080>
ServerAlias *
ServerPath /app2/
WSGIScriptAlias /app2 /home/eyuelt/app2/app2/wsgi.py
Alias /app2/static /home/eyuelt/app2/staticfiles
<Directory /home/eyuelt/app2/app2>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
<Directory /home/eyuelt/app2/staticfiles>
AllowOverride None
Order Deny,Allow
Require all granted
</Directory>
</VirtualHost>
I suspect this might be the problem:
http://httpd.apache.org/docs/2.2/vhosts/examples.html
This is what you want: You have multiple domains going to the same IP
and also want to serve multiple ports. By defining the ports in the
"NameVirtualHost" tag, you can allow this to work.
One or both of these could be the problem: If you try using
without the NameVirtualHost name:port or you
try to use the Listen directive, your configuration will not work.
Server example:
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080
<VirtualHost 172.20.30.40:80>
ServerName www.example.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.com
DocumentRoot /www/domain-8080
</VirtualHost>
<VirtualHost 172.20.30.40:80>
ServerName www.example.org
DocumentRoot /www/otherdomain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.org
DocumentRoot /www/otherdomain-8080
</VirtualHost>