mediawiki instance served by apache on specific domain - apache

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.

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

Allow Cachet to run with other sites

I have installed the open source status page Cachet on my macbook's local web server and it works perfectly but during the set up it tells you to change your apache's virtual host to route all traffic to Cachet. I am trying to allow Cachet to run by going to the main domain but if I go to domain/test I would like it to go to another web page. I tried adding another vhost like this:
<VirtualHost *:80>
ServerName http://domain/test
DocumentRoot /Users/macbook/Sites/
</VirtualHost>
but this does not work, I just get error 404 when trying to reach /test page.
Cachet is built using the Laravel framework, so there is a front controller in the public/ directory. That's why you need to route all the requests to this file. But you do not need to route all the traffic of your server to Cachet, that's just the traffic of the site (Cachet), in order to /setup and others are executed by /public/index.php.
Your vhost file may be simple, below an example of what it could be.
It is a simple vhost configured in Mamp, on OSX.
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/Cachet/public"
ServerName status.mysite.com
<Directory /Applications/MAMP/htdocs/Cachet/public>
AllowOverride All
</Directory>
</VirtualHost>
The routing to the public/index.php file is performed by a .htaccess file, so you don't have to write this configuration in your vhost. All you need to do in your vhost is to allow the .htaccess execution.
Note for local web server
If you want to use a custom domain name, you'll need to
update the /etc/hosts file to match the domain with your loopback IP
address.

Subdomains with Apache Virtualhost

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?

Apache Non-Vhost Redirect

I want to force all server requests not matching one of my configured vhosts to redirect to my company's home page?
Currently my primary DocumentRoot is set to my home site directory, so non-vhost request do serve home page content; however, the domain name does not change. How can I force this?
Also, my primary ServerName is commented out by default. Is setting this recommended? And if so, why?
The first virtual host found in the apache config will be the default host if there is no ServerName match. So add a default host first that redirects to your companies home page:
<VirtualHost *:80>
ServerName myserver
Redirect 301 / https://www.example.com/
</VirtualHost>
If you have more than one IP address and different listeners x.x.x.x:80 then it can be a bit more complex as apache actually looks for a match on the combination of listener and servername. But it's not hard to resolve.
If the primary servername is commented out then apache will try to figure this out at start up. It's usually not an issue when using VirtualHost directives with ServerName local to each vhost.

Subdomains on WampServer

I'm working on WampServer for development, I've set up the domain tuniguide.local It works fine with this configuration:
DocumentRoot "D:\www\tuniguide"
ServerName tuniguide.local
But when I wanted to add a subdomain fr.tuniguide.local I get a 404 Not Found with this configuration:
DocumentRoot "D:\www\tuniguide\fr"
ServerName fr.tuniguide.local
It gives me this message:
The requested URL /www/tuniguide/index.php was not found on this server.
Is there someting that I missed?
Thanks.
You may need to edit your host file on your server machine to have it point the correct domains to your localhost. Check out this in depth tutorial on subdomains for Wamp here: http://www.itutorblog.com/2011/06/how-to-create-a-subdomain-on-wamp/