Domain for main document root gets pointed to newly enabled subdomain document root - apache

I have a Ubuntu 16.04 which apache2 server is running. I have a website hosted in my primary domain which the document root is /var/www/html.
I use Webmin to create a subdomain and I have given the document root as /var/www/mysite.
when I restart the server and visit the main domain, it shows the website that I hosted in the /var/www/mysite, which is the subdomain document root.
If I remove or rename the conf file under /etc/apache2/sites-available/{created-subdomain.conf} file, the main domain again shows the website hosted in the /var/www/html document root.
What are the possible causes for this. I want my main domain to show the website I hosted in /var/www/html and subdomain to show the website I placed in /var/www/mysite

Sounds like you're not setting up ServerName domain.com in your configs, so Apache simply chooses the first one (alphabetically by Config file name) to serve.

Related

Domain Name cannot be changed in Apache on CentOS 7

I have set up a server with a wiki and Wordpress and Nextcloud on a new Domain, let's say it's testing.com. When I was finished, I wanted to change the Domain from testing.com to realdomain.com.
The server is running CentOS 7 with httpd (apache), so I changed the ServerName in /etc/httpd/conf/ to "realdomain.com". Then I changed the VirtualHosts in all the files in /etc/httpd/conf.d.
I added the new Domain to the trusted Domains of the Wordpress, Nextcloud and wiki. I restarted the httpd service and the server itself.
Yet, when I open realdomain.com in browser, it shows me my websites, but it puts testing.com in the address field.
I tried using mod_rewrite to change the URL, but then my webbrowser tells me that the site doesnt redirect correctly and that the redirects never stop.
I tried those rewrite rules in the .conf files and in the .htaccess (not simultaneously)- no success.
I removed all my files in conf.d and created a new DocumentRoot with a simple helloWorld.html - The Url still gets rewritten to testing.com.
Are there any other locations that could have rewrite rules? Did I miss anything?
Thank you so much in advance, this is killing me!

DigitalOcean hosting with GoDaddy domain denying access to root directory

I own a domain on GoDaddy and am attempting to point it to my DigitalOcean-hosted website. Here are the steps I have taken so far:
I cloned the git repo containing all of my website files from local to my DigitalOcean server.
I added an # record on godaddy for my domain and pointed it to my DigitalOcean IP address.
IMPORTANT!! I modified /etc/apache2/sites-enabled/000-default.conf with my new VirtualHost pointing mydomain.com to index.html, NOT THE ROOT DIRECTORY.
I then proceeded to do 'service apache2 restart' while sshed to DigitalOcean on terminal.
I assumed this would work and then tested it out and went to mydomain.com. Not so much. This is the error I got:
Forbidden
You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at mydomain.com Port 80
This was obviously pretty surprising given that it was not redirecting to index.html, so I manually appended /index.html to mydomain.com only to find that it gave me an identical error only I could not access /index.html instead of /.
I have done this kind of things many times before, however I used subdomain records for godaddy on an existing domain instead of using a brand new domain with no subdomains. Where did I go wrong?
Thanks!
Brandon
UPDATE: I tried on a test subdomain with test.mydomain.com and got this new error:
Not Found
The requested URL / was not found on this server.
Apache/2.4.7 (Ubuntu) Server at test.mydomain.com Port 80
You noted you modified the virtual host to point to index.html but not the root directory. Apache would still use the root directory (DocumentRoot) to locate the index.html file. If it is looking in the wrong location it could explain the 403 error (looking in a place that the web server user [www-data] cannot read as an example).
Beyond that, a 403 like that could be permission related. You would want to ensure the DocumentRoot and index.html file have the ownership of www-data:www-data and they are all readable by the web server itself (755 for folders and 644 for files is the norm).

Apache Web Server - How do I make my index page point to one of the folders

I have establish a web server on ubuntu.I have created some web sites on apache, each site has different folder.
In order to browse to my site website1 for example I need to type mymachine/Website1.
I want to type mymachine and it will redirect to the folder website1 , i.e. to my website.
Any suggestion, tried several settings.
Thanks
You have to it with Virtual hosts option,
first: you need to make specific folder in /var/www/..
second: point your folders with ServerName in Virtualhost file

Hosting personal pages over a Redmine installation

I currently installed redmine on my server, and configured apache2 to run it in a virtualhost over mydomain.com
Thing is I also want to host some extra pages, at mydomain.com/personal, but since redmine is running the page is never found. How can I override this configuration to run both redmine and some personal pages?
You need the Alias directive to just create a virtual directory, which maps /public with some other real directory on the filesystem.

Magic Apache redirecting for /~username

I have inherited a webserver already serving some websites. I am trying to migrate some of those sites to a new webserver.
One of those websites has a page called:
http://mydomain/ABCDepartment/
This URL also works:
http://mydomain/~joesmith
and the index page for joesmith actually lives in /var/www.../ABCDepartment/people/joesmith/
Now I am checking in httpd.conf and I see the following:
UseCanonicalName Off
UserDir public_html
UserDir disabled root
There are no special mod_rewrite rules for joesmith or the ~
How is this magic happening? UseCanonicalName is off, and if it wasn't UserDir public_html should look in /home/joesmith/public_html
What am I missing?
This is an Apache extension called userdir: http://httpd.apache.org/docs/1.3/mod/mod_userdir.html
It automatically rewrites requests to point to a folder called public_html within the user's home directory (the web server must have read access up the tree to this folder).