Add subdomain on Apache2 - dns

I want to add a subdomain api.example.com on Apache2.
Here is my configuration file for the domain.
<VirtualHost *:80>
ServerName api.winity.pw
ServerAdmin webmaster#winity.pw
DocumentRoot /var/www/api
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I tried to access it without working, here is my DNS configuration on CloudFlare
When I try to access it, I find myself in the /var/www/public directory and not /var/www/api.

First when asking here.
Google the question
Search on StackOverflow
Make a relevant title for you Create subdomain in Apache2
Specify your operating system not your type of server**
Use 443 port over SSL by changing <VirtualHost *:80> to <VirtualHost *:443>.
If you receive an HTTP 525 - SSL Handshake failed error from CloudFlare, use Flexible SSL option.
This append when you use Full SSL and you don't have a valid SSL certificat on your server.
For fix this issue, change the SSL option to Flexible.

Related

How to configure linux/apache for multiple virtualhost in local machine

I have two local web site project, localgoogle.com and localapple.com.
localgoogle.com files are in /home/vahid/dev/localgoogle
localapple.com files are in /home/vahid/dev/localapple
My OS is debian 8.5, I have apache2 installed.
I made /etc/apache2/sites-available/localgoogle.com.conf
and /etc/apache2/sites-available/localapple.com.conf
both linked to /etc/apache2/sites-enabled and enabled by a2ensite command.
This is localgoole.com.conf:
<VirtualHost *:80>
ServerName localgoogle.com
ServerAdmin webmaster#localgoogle.com
DocumentRoot /home/vahid/dev/localgoogle
ServerAlias www.localgoogle.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
localapple conf file follow above configuration rule.
I restarted apache2 service, but I don't know why and how to access this virtualhosts from browser!
I tried localhost/localgoogle.com in browser but It's return Not Found
You access the site directly as localgoogle.com from your browser. Make sure that the name resolves to your local ip address using hosts file or dns.

Serving same content in same ip address with different domain names

An Apache web server for the domain “www.abc.lk” is configured and hosted in a hosting server with the IP address 192.168.2.105. Another domain called “www.def.lk” should also be configured with the same content without any duplication. Explain the configuration of the Apache server with name-based virtual hosting for the above requirement?
You have to configure two virtual host with same DocumentRoot but different ServerNames
http://httpd.apache.org/docs/2.2/vhosts/examples.html
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.abc.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.123.com
# Other directives here
</VirtualHost>
Why don't you just use www.abc.lk as ServerName and www.def.lk as ServerAlias in your vhost configuration ?
And of course be sure that both DNS point to the server.
Here is what I use (I think this link lays out all of the solutions or possibilities):
https://realtechtalk.com/Apache_Vhost_HowTo_Serve_Same_Content_using_a_different_domain_and_IP-1730-articles
Here is another way of doing it that is more simple than symlinking or duplicating content between vhosts:
This would be in your vhost.conf
ServerName differentdomain.com
ServerAlias www.differentdomain.com
ProxyPass / http://yourmainsite.com/
ProxyPassReverse / http://yourmainsite.com/

Set up SVN Server over https

I'm trying to get an SVN server up and running. CentOS 6.4, apache 2.2.15. More importantly, I need to have it running on https only. So I figure that I'll get ssl running first, as I've already tested it on port 80, and SVN works the way I want it to.
In /etc/httpd/ssl, I have ..
intermediate.crt wildcard.mycompany.com.crt wildcard.mycompany.com.key
We bought a wildcard certificate from GeoTrust, and I downloaded the intermediate.crt from their website. In /etc/httpd/httpd.conf, I have..
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin my.email#mycompany.com
ServerName hostname.mycompany.com
ErrorLog logs/error_log
CustomLog logs/access_log common
Redirect permanent / https://hostname.mycompany.com
</VirtualHost>
<VirtualHost hostname.mycompany.com:443>
SSLEngine On
SSLCertificateFile /etc/httpd/ssl/wildcard.mycompany.com.crt
SSLCertificateKeyFile /etc/httpd/ssl/wildcard.mycompany.com.key
SSLCertificateChainFile /etc/httpd/ssl/intermediate.crt
ServerName hostname.mycompany.com
ServerAdmin my.email#mycompany.com
ErrorLog logs/subversion-error_log
CustomLog logs/subversion-access_log common
</VirtualHost>
I can connect to the server, but my browser tells me that the certificate is untrusted. So I'm guessing that there's an error in the permissions, or perhaps in the format of the file?
I can't see anything in the logs.
I set this up at home on my own server, but wasn't using a wildcard certificate.
Anyone care to advise as to what's gone wrong?
Thanks.

Apache2 - Trouble Adding Subdomain

I have a Linode server running Ubuntu 11 and Apache2 and I'm trying to get a subdomain working. This is my mywebsite file in sites-available folder. I've tried putting the top part in its own file testing.mywebsite and reloading apache2 with no luck.
<VirtualHost *:80>
DocumentRoot /home/user2/www
ServerName testing.mywebsite.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin email#gmail.com
ServerName mywebsite.com
ServerAlias *.mywebsite.com
ServerAlias 192.155.90.135
#Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/user/public/mywebsite/www
#Log file locations
LogLevel warn
ErrorLog /home/user/public/mywebsite/log/error.log
CustomLog /home/user/public/mywebsite/log/access.log combined
</VirtualHost>
I have a website up and running and apache can find all the files in /home/user/public/mywebsite/www but when I go to the testing subdomain, my browser can't find it. I'm pretty unfamiliar with apache2, so any help is appreciated. Thanks.
Are your DNS records configured to point your computer at the desired hostname to your server's IP address when it resolves? Or, are you overriding with editing /etc/hosts?
I am somewhat unsure what "my browser can't find it" means, so please clarify if the above questions don't get you closer to your problem. It would be worth checking your log files for Apache in your specified paths and /var/log/apache2/.

Apache Virtual Host - xxx.241.214.xxx:80 has no VirtualHosts

I'm trying to set up a virtual host on a new VPS using apache 2.x on a Ubuntu server.
When starting apache I get the error " xxx.241.214.xxx:80 has no VirtualHosts", and the url for the site still points to the default location which means my virtual host file isn't taking effect:
<VirtualHost xxx.241.214.xxx:80>
ServerName xxx.co.uk
ServerAlias www.xxx.co.uk
DocumentRoot /var/www/vhosts/xxx.co.uk/httpdocs/xxx.co.uk
</VirtualHost>
Please help, I'm no good at all this server config stuff.
I know its been a while since you posted your question but I thought id throw in my thoughts
We currently run a few internal sites here for different purposes, all of them listen of standard port 80 and apache is set up simply as follows
Listen 80
NameVirtualHost *:80
# Site 1 Comment
<VirtualHost *:80>
ServerName site1.intranet
ServerAdmin administrator#whatever.com
DocumentRoot /var/www/html/site1
</VirtualHost>
# Site 2 Comment
<VirtualHost *:80>
ServerName site2.intranet
ServerAdmin administrator#whatever.com
DocumentRoot /var/www/html/site2
</VirtualHost>
Our DNS is set up to route http://site1.intranet etc to the IP of the apache server and the apache config does the rest.
I always use
<VirtualHost *>
(and ISTR always having problems specifying the IP and port number, which I think is why I do it that way now).

Resources