How to setup subdomain/domain with and without www prefix on localhost - apache2

I went through lots of SO questions but non is giving me the right answer .
I have following config in apache vhost:
<VirtualHost *:80>
DocumentRoot "D:/Web Server/xampp/htdocs/testsite/frontend/www"
ServerName mydomain.com
ServerAlias www.mydomain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/Web Server/xampp/htdocs/testsite/backend/www"
ServerName admin.mydomain.com
ServerAlias www.admin.mydomain.com
</VirtualHost>
AND hosts file :
127.0.0.1 testsite.com
127.0.0.1 admin.testsite.com
What I need is that:
www.testsite.com and testsite.com should point to same thing
and same with
www.admin.testsite.com and admin.testsite.com
What is the issue with this config ?
Do I need to add separate records for each , one with www and other without www ?
please help me sort this issue
thanks in advance

You need to add the www. versions of your domains to your etc hosts.
127.0.0.1 testsite.com www.testsite.com
127.0.0.1 admin.testsite.com www.admin.testsite.com

Using CNAMEs makes your DNS data easier to manage. CNAME-records point back to an A record. So if you change the IP address of the A record, all your CNAME records pointed to that record automatically follow the new IP of the A record. The alternative solution is to have multiple A records, but then you would have multiple places to change the IP address which increases the chances of error.
The most popular use of the CNAME-record, is to provide access to a web server using both the standard www.domain.com and domain.com (without the www). This is usually done by adding a CNAME-record for the www name pointing to the short name [while creating an A Record for the short name (without www)].
Example:
You have a website with the domain name mywebsite.nl. This domain name is hooked up to an A-record which translates the domain name to the appropriate IP address, f.i. 11.22.33.444.
You also have several subdomains, like www.mywebsite.nl, ftp.mywebsite.nl, mail.mywebsite.nl etc. and you want this sub domains to point to your main domain name mywebsite.nl. In stead of creating A-records for each sub domain and binding it to the IP address of your domain, you create an alias, a CNAME-record. See the table below, in case your IP address changes, you only have to edit 1 A-record and all subdomains follow automatically because de CNAMES point to the main domain with the A-record.
(Sub)domain
Type
Target
mywebsite.nl
A
11.22.33.444
www.mywebsite.nl
CNAME
mywebsite.nl
ftp.mywebsite.nl
CNAME
mywebsite.nl
mail.mywebsite.nl
CNAME
mywebsite.nl

Related

VirtualHost Apache2 seems ignored - only my local hosts file gets things working, despite DNS propagation

Newbie/wannabe/failing webmaster here...I have a Google VM Debian9 instance running Apache2. For the past few months, i had no domain name, so i faked one using a virtual host (crm.fake_example.com) since i was the only user. I added the IP and my fake address to my local hosts file, and everything worked just fine as I stood up a web-based, open source software application on the VM.
I've now pointed a subdomain (crm.real_example.com) to the IP address of my VM. I've waited a full week for DNS propogation (yes, overkill) and have used MXtoolbox - DNSLookup to verify that the subdomain resolves to the correct IP address. I erased any previous entries to my local hosts file.
Visiting the site from my local machine (or any machine) yields the same error ("ERR_NAME_NOT_RESOLVED").
However, if I edit my local hosts file to include the IP and crm.real_example.com...it works just fine again.
I feel like MXtoolbox proves to me that DNS is working, so the problem must exist on my VM somewhere (can someone verify this thinking?) - but I've checked/re-checked all of the following...
On the Google VM apache2 server:
/etc/hosts is a clean file (nothing from crm.fake_example.com exists in there any longer)
/etc/apache/sites-available/mysite.conf has the necessary virtual host info (see below)
note: I know virtual host is not required for only one site...but i plan to add more so want it working using this
/etc/apache/sites-enabled/mysite.conf activated via a2ensite
config.inc.php (a vtigercrm-specific config file) has been reconfigured for crm.real_example.com
<VirtualHost *:80>
ServerAdmin me#real_example.com
ServerName crm.real_example.com
DocumentRoot /var/www/html/crm/
<Directory /var/www/html/crm/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/crm_error.log
CustomLog /var/log/apache2/crm_access.log combined
</VirtualHost>
I could also list all the things i've done on my local machine like clearing DNScache, cleaning up my hosts file, etc...but the same thing happens from any other machine with no previous successful attempts at hitting this server.
After a full week of looking at the same things over and over...any guidance is appreciated!

Accessing website on wamp server using Android mobile [duplicate]

So I set up a few virtual hosts with unique urls and they work just fine on the desktop. However, when I connect a mobile device on the network, it can't seem to access anything properly but the default localhost virtualhost and that's only when it's the only virtualhost I have up.
My setup and coding is pretty much this except with a different site title
wamp server 3.0 virtual host on another device
and while that solution redirects me to my unique url, it has a lack of images on a default wordpress website.
Has anyone managed to get mobile devices fully accessing links other than on localhost?
Since I posted the answer you referenced, I have decided upon a simpler solution.
What the actual problem is
Because we cannot fiddle with the configuration of a phone like we can with a PC, the phone can never find the domain name we create in our Virtual Host definition on the Server machine, because it does not exist in any DNS Server for it to locate the IP Address in, and a DNS Server is the only place a phone can look, unless it is jail broke.
If you wanted to access one of your Virtual Hosts domains from another PC you could just add a line like this into the HOSTS file on the other PC like this.
192.168.0.10 example.local
But you cannot do that on a phone/tablet.
What Apache expects to be able to asssociate a request to a Vhost
When we create an Apache Virtual Host, we are actually telling Apache to look at the domain name on the incoming connection and match that domain name to a ServerName that exists in one of our multiple Virtual Hosts definitions.
But if we use for example example.local as our virtually hosted domain when we attempt to connect to that from our phone, the phone does a DNS Lookup and does not find that domain and therefore cannot get its ip address.
The simplest way to get round this is:
Assuming we do not have access to adding record to a DNS Server we have to come up with a different solution.
The simplest of these is to use the IP Address of the PC running the WAMPServer(Apache) server and a specific port number. So thats a different port number for each of our sites we want to use from a phone.
So how do we do this
Add the new listening port to httpd.conf like so after the 2 existing Listen statements
WAMPServer 3: Do this using the menus, not by doing a manual edit on httpd.conf
right click wampmanager-> Tools -> Add listen port for Apache
#Listen 12.34.56.78:80
Listen 0.0.0.0:80
Listen [::0]:80
Listen 0.0.0.0:8000
Listen [::0]:8000
Suggested httpd-vhosts.conf file
#
# Virtual Hosts
#
# Always keep localhost, and always first in the list
# this way a ramdom look at your IP address from an external IP
# maybe a hack, will get told access denied
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp/www
<Directory "c:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# The normal Vhost definition for one of our sites
<VirtualHost *:80>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# Access example.dev from phone for testing
<VirtualHost *:8000>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
# assuming yoursubnet is 192.168.0.?
# allow any ip on your WIFI access
Require ip 192.168.0
</Directory>
</VirtualHost>
Restart Apache from wampmanager after completing these edits.
Now you test this from the WAMPServer PC by using the ServerName i.e example.dev and from the phone using the ip of the PC running WAMPServer with the port number i.e. 192.168.0.10:8000
Apache will find the correct code to serve from both requests.
If you want more than one Virtual Host to be accessible from your phone you just duplicate this idea and change the port number for each new site, lets say you would use 8001,8002,8003 etc. For as many sites as you want to access.
You may also have to amend your firewall to allow access on http on port 8000, or whatever port you pick to use

Fixing domain display on directory redirects

I have multiple domains directing to multiple directories on my system, as an example...
shopwebsite.co.uk > public_html/useraccounts/shopsite
carwebsite.co.uk > public_html/useraccounts/carsite
foodwebsite.co.uk > public_html/useraccounts/foodsite
This has been okay for a while until I realized that framed forwarding caused the mobile responsiveness to stop responding and so I changed all of the domains to simple redirects. This does work although as you can now work out, whenever somebody types in one of these URLs the website displays as something like:
https://mymainwebsite.co.uk/useraccounts/foodsite
Which is causing a few problems for me in various ways. What I am looking to achieve is to attach each domain to its directory path while keeping the URLs and being able to use the domain properly while also keeping mobile responsiveness.
Now this may seem like a really simple situation although I have a couple different domain hosts and my website hosting is via Hostinger, so I am not able to manipulate certain back end features, making it slightly more difficult for me. I am also still learning and really don't have much knowledge in DNS, IP forwarding, etc so I wouldn't know what I'm looking for?
If somebody can point me in the right direction I can more than likely figure the rest out on my own. I can access my htaccess file for the main website as well as DNS and ability to park domains etc...
Hope somebody can help me find a solution. Thanks.
I think you are looking for something called "Virtual Host". This is a configuration of the web server that allows you to run multiple web sites on the same server. In Apache simple virtual host looks like this:
<VirtualHost *:80>
DocumentRoot "/public_html/useraccounts/shopsite"
ServerName shopwebsite.co.uk
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/public_html/useraccounts/carsite"
ServerName carwebsite.co.uk
# Other directives here
</VirtualHost>
There are no redirects in this method. The browser is connecting to the webserver and is sending "Host" header - the domain name typed in the URL, then it returns the files from the directory you configured in "DocumentRoot" directive for this "ServerName".
You should call your hosting provider support team and ask them how do you manage virtual hosts.

View local website from Android phone

I have a mobile website locally hosted in IIS7. I want to view it in my android phone. This is not the usual case of accessing 127.0.0.1, which I have done already.
I set an inbound rule in Firewall for port 80. My IP, assigned by router, 198.162.2.10, which when open in my mobile shows the IIS7 image.
The problem I face is, I usually do the project in D:\ drive than in wwwroot, not to loose any files in case of OS crash or re-install. So to link these projects, I create a website in IIS and give a naming like myprofile.net and assign it to 127.0.0.1. So when I type myprofile.net in the browser, the website is rendered.
How do I access this website, from my android phone?
I know a "workaround" to
copy all the websites into wwwroot? That negates the main point.
connecting phone to PC's ad-hoc or vice versa? I don't want this, either of this puts my computer from internet, and developing without internet is impossible.
upload to ftp server and view from phone? This is what I am currently doing.
Is there a solution?
You could make a symlink to your websites' files on the D:\ to your wwwroot directory.
Here's a tutorial link
and a custom command for you:
C:\mklink /D C:\path\to\wwwroot\NameOfWebsite D:\path\to\website\to\create\the\symlink\for\NameOfWebsite
Also if you may need to updated your virtualhost file... I use apache, been 6+ years since I used IIS :/ so hopefully this is relevant:
example of what you'll want to change:
<VirtualHost *:80>
ServerAdmin gopikrishna.s#gmail.com
DocumentRoot "C:\path\to\wwwroot\NameOfWebsite"
ServerName NameOfWebsite
<Directory "C:\path\to\wwwroot\NameOfWebsite">
Options Indexes FollowSymLinks ExecCGI MultiViews #NOTE THESE OPTIONS Follow SymLinks is NEEDED
AllowOverride All
Order allow,deny
Allow from all
</Directory>
#EXAMPLE alias if you have any.
#Alias /graphics "D:/workspace/graphics"
</VirtualHost>
You will also have to update the hosts file located normally in
C:\Windows\System32\drivers\etc
right click notepad and run as administator to make edit's to the system file hosts.
click File->Open
locate your hosts file directory
change Text Documents (.txt) to All Files (.*) to see the hosts file (among others)
open the hosts file and add this line to the bottom of the file:
127.0.0.1 NameOfWebsite
This line should have the same name you put as your ServerName in your httpd-vhosts.conf file or the IIS equivalent.
Save the hosts file and reset your IIS server
Now you should be able to run in your android's browser (if connected to your local router which the IIS server is also connected to) the web server's IP address which as mention in your post would be
198.162.2.10
and that should show your websites in your android's browser.
Also be sure to put which ever website you want to see in your browser at the top of any other vhost configurations.
That is to say:
in your hosts file make sure if their are other lines like
127.0.0.1 some.site.local
127.0.0.1 another.site
127.0.0.1 NameOfWebsite <------ This should go
That you put the one you want to see at the top of the list like so:
127.0.0.1 NameOfWebsite <-------- HERE
127.0.0.1 some.site.local
127.0.0.1 another.site
And for the httpd-vhosts.conf file make sure the whole ........
Section is above all others.
I hope this helps a bit, feel free to add anything or subtract anything changes are more than welcomed. Forgive me if I over spoke on this post or gave details you already knew.
I think the symlinks are basically all you need, but the other stuff probably will help as well.

Add www prefix to a domain in Plesk Parallels

I have just set up my first domain in plesk (v10 I think? Newest version). I am used to using shared hosting where the www is set up, but upon setting up my domain only http://retapy.com will work, and http://www.retapy.com wont work. I have had a look on here and on other forums and have since changed the domain name in the control panel to "www.retapy.com", but now it doesnt work without the "www." prefix.
I am also wondering, if the domain is set to "www.retapy.com" in the control panel, will I be able to set up other sub domains after?
I would like to use .htaccess:
RewriteCond %{HTTP_HOST} ^retapy.com
RewriteRule (.*) http://www.retapy.com/$1 [R=301,L]
But cant do this as it isnt recognising http://retapy.com at all.
What is the best way to set this up?
I read about having the domain set up as just retapy.com (no prefix) and have a "www" folder in the httpdocs folders which is simply a shortcut to the main folder, but I am now completely lost.
Looks like your domain hasn't www DNS record.
Check DNS zone in your domain registrar web site and add "www" cname or a record for domain.
I've checked one DNS server of you domain:
[~]# nslookup www.retapy.com NS0.VPS380574-1.LCNSERVERS.COM
Server: NS0.VPS380574-1.LCNSERVERS.COM
Address: 178.18.126.170#53
** server can't find www.retapy.com.qa.plesk.ru: REFUSED

Resources