Subdomains with Apache Virtualhost - apache

I have a server and registered a domain - say mysite.com - that is pointing to the IP address of the server. I tested the setup with a django project in the default.conf file. This works without a flaw, but my goal is to move this django site to a subdomain. As this didn't work as expected, I tried to get a minimal example working with a redirect.
This is what I have:
sites-available/sub.conf
<VirtualHost *:80>
ServerName sub.mysite.com
RedirectPermanent / https://google.com/
</VirtualHost>
I enabled the site via a2ensite sub and service apache2 reload. When visiting sub.mysite.com all get is
Server not found
What am I missing?

Related

How do I configure apache to return 404 on unconfigured subdomains?

I am self-hosting a website on a Debian computer with apache, and in my DNS configuration I have set all subdomains of my domain (*.mydomain.com) to go to the IP of my Debian computer. How do I configure apache so that if someone goes to a subdomain that doesn't have a virtual host, I have a separate file for each subdomain, they get a 404 error instead of seeing the content on the root domain? I have tried editing the 000-default.conf file and put the following in it:
<VirtualHost *:80>
ServerName null
Redirect 404 /
</VirtualHost>
<VirtualHost *:443>
ServerName null
Redirect 404 /
</VirtualHost>
But now when I got to mydomain.com I get the following error:
This site can’t provide a secure connection
mydomain.com sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
Oddly if I go to one of the subdomains that I have configured for mydomain.com it works correctly and I see the page that should be on the subdomain.
Your connection is not private
error messages comes from the certificate used which is probably not valid for the domain you're connecting to.
Wilcard certificates such as *.mydomain.com are valid for 'third-Level.mydomain.com' but NOT for 'somthing.third-Level.mydomain.com' which requires a wildcard like '*.third-Level.mydomain.com'.
You can get free and valid wildcard certificates from Let's Encrypt (https://letsencrypt.org/)
And, instead of adding port 443 to 000-default.conf, use the default-ssl.conf file. Enable default-ssl.conf using a2enconf default-ssl, and then remove the 443 from the 000-default.conf. And then, restart/reload apache using systemctl restart apache2

mediawiki instance served by apache on specific domain

So, I use MediaWiki, hosted by Apache (wiki dir is in /var/www/html/wiki).
I have my domain www.my-domain.com which is redirected through apache virtual host to port 8080 for some nodejs app.
I have now tried to set up my wiki to be served on http://wiki.my-domain.com
In my DNS records i have both www and wiki domains redirected to same server.
First I tried to make apache virtual host to handle domain request:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName my-domain.com
ServerAlias wiki.my-domain.com
DocumentRoot /var/www/html/wiki
</VirtualHost>
However if I tried to connect to wiki.my-domain.com or wiki.my-domain.com/wiki I got the message that the page doesn't exists.
I went to check my wiki's LocalSetting.php
and I tried editing this line:
## If i changed value to this, it didn't worked
$wgServer = "http://wiki.my-domain.com";
## If i set value to this, it was working
$wgServer = "http://my-server-IP";
However, if i set wgServer to my server IP, whenever i write http://wiki.my-domain.com, i get redirected to http://my-IP/wiki instead of staying on domain name
I would appreciate the help on how to properly set up my wiki's or apache's settings to properly host my wiki on my domain.
I found the problem:
$wgScript was set to:
$wgScript="/wiki"
and needs to be set to:
$wgScript=""
since Apache was redirecting the domain already to my /wiki folder, there was no need for script to also redirect it there and this was causing problems.

Q: Disable access to default vhost and through server IP on Apache 2.4.10

I'm trying to get Apache 2.4.10 on Debian 8 "Jessie" up and running with multiple websites hosted on it. This might be an obvious and already answered question but I've never had the need to set-up a dedicated web host (usually just drop a WAMP server for development needs or pick up a web hosting service) and so far I have not had any luck finding an answer to my problem (I've found the complete opposite answers of what I'm trying to achieve). I need to get this working because apart from just hosting a couple of websites, there will be additional software set-up, for which, a regular web hosting service won't do.
Everything seems to be working as intended but the only problem is that I can't seem to find an optimal configuration which wouldn't just block access to default vhost with 403 - Forbidden. What I need is Apache to ignore requests (not just return a 404 document but tell the browser there's nothing there) from anyone accessing the default vhost or by accessing the server directly through it's designated IP. The designated IP should be left for SSH access only (since I don't have any kind of physical access to this server).
Basically, the web server should be accessible from a web browser through "FQDN-1" and "FQDN-2" (each located in their individual directories) and access to any other web address on this server should be ignored (invoking browser "404 not found" instead of returning a server error document, which would indicate that something is there).
my current vhost files:
<VirtualHost *:80>
ServerName FQDN-1
ServerAlias www.FQDN-1
ServerAdmin mail#FQDN-1
DocumentRoot /var/www/FQDN-1/public_html
ErrorLog /var/www/FQDN-1/logs/error.log
CustomLog /var/www/FQDN-1/logs/access.log combined
</VirtualHost>
And
<VirtualHost *:80>
ServerName FQDN-2
ServerAlias www.FQDN-2
ServerAdmin mail#FQDN-2
DocumentRoot /var/www/FQDN-2/public_html
ErrorLog /var/www/FQDN-2/logs/error.log
CustomLog /var/www/FQDN-2/logs/access.log combined
</VirtualHost>
The default vhost has been disabled through "a2dissite 000-default"
Iptables block everything except tcp port 80 and 22 (SSH access is whitelisted in iptables to just few specific iPs).
You can let the built-in name-based vhosting do the work for you. You can simply setup an additional (non default / non-first listed for *:80) virtualhost with
ServerName your-ip
and put a simple rule like
RewriteEngine ON
RewriteRule ^ .* [F]
or
Redirect 403 /

IP of Web server stays in URL instead of showing Domain Name

So lets say I have the Domain Name "www.example.com" and have a "http-redirect" to server "1.1.1.1" where apache2 is running on Ubuntu 14.04 Server amd64.
I have all my web files on the server and they are working perfect.
What is not working right is the URL. Instead of "www.example.com/sites.php" if have "1.1.1.1/sites.php". How can I fix this?
What I did so far:
Disabled the default Virtual Host and created a new one:
<VirtualHost *:80>
ServerAdmin bla
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www
ErrorLog ...
CustomLog ...
</VirtualHost>
(It's typed, since I can't copy from my console..)
I tried to enter in the /etc/hosts
1.1.1.1 www.example.com
Thanks for any help
As discussed in comments, the reason that you see IP address in your browser is that http-redirect is pointing directly to to IP address, there's no domain name to display. Redirect just tells browser to go elsewhere and browser then fetches website from supplied URL, same as if you'd click on a link. If you redirect URL to 1.1.1.1/sites.php than that is what you will see in browser.

Redirecting an internal path to a virtual host

I have been working on a drupal test site for a while, which has a bunch of virtual hosts set up like this:
<VirtualHost *:80>
ServerAdmin email#example.com
DocumentRoot "/path/to/root"
ServerName testsite1.example.com
</VirtualHost>
I have been using a modified host file to view each of these test sites, along the lines of:
12.0.0.1 localhost
20.02.2.22 testsite1.example.com
20.02.2.22 testsite2.example.com
20.02.2.22 testsite3.example.com
This has worked fine, however now I need to send the sites over to some people remotely who are not technical enough to modify their own host files and see it the way I do.
Is there a way I could set up Apache so that the url "http://20.02.2.22/testsite1" would forward to testsite1.example.com internally? I am using Drupal, and the site setup needs to see the "testsite1.example.com" so that it can correctly choose the instance to select. I have been looking through apache rewrite, but I am a bit of a newb at this so any help is much appreciated.
testsite1.example.com will only be resolved on your machine, so you cannot redirect. You can set up proxy with mod_proxy. Hope this works for you:
<VirtualHost *:80>
ServerAdmin email#example.com
DocumentRoot "/path/to/root"
ServerName testsite1.example.com
ServerAlias 20.02.2.22
<Location /testsite1/>
ProxyPass http://testsite1.example.com/
</Location>
</VirtualHost>
The way I show my local test sites is a combination of Dynamic DNS and port-forwarding.
Internally, my Drupal site is at [my machine ip] or localhost.
I setup a free dynamic dns name to my IP and then on my router, accept incoming requests on port to route to [my machine ip]
That way, they can see yoursite.dyndns.com, but its looking at your local copy.
Why you just don't buy a new domain name and point it to your server IP address...
Or there are free domain solutions like:
http://www.dot.tk/en/index.html?lang=en
or
http://dyn.com/dns/
If you wanna buy new domain, i recommending you this one, cheap and quality service: http://server2.elite7hackers.us/recommend.php?site=godaddy