How do I make my new website public? - apache

I have registered a new domain and set nameservers, A-records. I have also added conf files in my sites-enabled and sites-available directories under apache2 directory.
What would be the next step to lead incoming traffic to my appropriate site?
<VirtualHost *:80>
ServerAdmin admin#x.com
ServerName x.com
ServerAlias www.x.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

You seem to be missing the document root entry in your virtual hosts file. That is your next step to redirect traffic to your site.
Place this under server alias
DocumentRoot /var/www/x.com/public_html
Then you put your website in the folder /var/www/x.com/public_html. Make sure you modify the access rights so anyone can view the public_html contents
Check out this link for further details.
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

Related

Apache2 redirecting to main site

I'm trying to host multiple websites off a digitalocean droplet using apache2's virtualhosts.
I have a config file for the main one, (pcnerd19.com) and one for the other, (efferri.ga). Whenever I type efferri.ga in firefox though, it just redirects back to pcnerd19.com I've restarted apache2, and made sure both sites are enabled. The is an index file at the root of efferri.ga as well. Here are my config files.
pcnerd19.com:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName pcnerd19.com
ServerAlias www.pcnerd19.com
ServerAdmin ruby#pcnerd19.com
DocumentRoot /var/www/wordpress1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/pcnerd19.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/pcnerd19.com/privkey.pem
</VirtualHost>
<Directory /var/www/wordpress1>
AllowOverride All
</Directory>
<IfModule>
efferri.ga:
<VirtualHost *:83>
ServerName efferri.ga
ServerAlias www.efferri.ga
ServerAdmin ruby#pcnerd19.com
DocumentRoot /var/www/efferri
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
It is worth mentioning I used certbot to get an ssl certificate on pcnerd19.com, and my droplet is running Debian.
From this page where someone had a similar problem, this answer might help:
When looking at your VirtualHost configuration, you’re setting a ServerAlias that defines the www. access point for each domain, but you’re missing a DNS entry on both domains that points www. to your domain. Since the DNS record isn’t set, Apache will handle it the best way it knows how, which may or may not be correct.
So what I would recommend doing is adding an A entry to each domains’ DNS records. The A entry should point to the same IP that your domain points to (i.e. the public IP of the Droplet).
So www should be an A entry that points to 46.101.19.243 in your case. Since it looks like your using DigitalOcean for your DNS, you can make these changes through their control panel and the updates should take effect pretty quickly. If they don’t, you may need to clear your browsers cache and then try to access your domains again.

Domains crossed over on digital ocean

I have two domains. exampleone.com and exampletwo.com.
I followed this guide for adding multiple domains on the same server:
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
They are both on the same server. Somehow, blog.exampleone.com was created (out of nowhere). and it points to exampletwo.com.
If I click on the site in google, it shows blog.exampleone.com as the domain, but shows the content for exampletwo.com
How is this happening?
I've looked into the vhost files and everything seems correct.
Here is a sample vhost file:
<VirtualHost *:80>
ServerAdmin dave#example.com
DocumentRoot /var/www/html/exampleone.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.lognano
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This should result in 2 separate sites on the same server. Instead, a blog subdomain was created on one site that points to the content on another site.
What should I do?
Thanks!
You neeed to specify the "ServerName" in your vhost file, something like :
<VirtualHost *:80>
ServerAdmin dave#example.com
ServerName blog.exampleone.com
DocumentRoot /var/www/html/exampleone.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.lognano
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
in fact, for each vhost file, you need to specify the ServerName to work properly with your subdomains!

virtual host not able to access file outside document root

I have setup virtual hosts for separate projects on my localhost on my macOS. Here is the httpd-vhosts.conf file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Users/Sammy/Sites"
ServerName 127.0.0.1
ServerAlias localhost
ErrorLog "/private/var/log/apache2/localhost-error_log"
CustomLog "/private/var/log/apache2/localhost-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/Sammy/Sites/workspace/abc/public_html"
ServerName abc
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/Sammy/Sites/workspace/xyz/public_html"
ServerName xyz
</VirtualHost>
I have also updated the list of hosts. The problem is, when I access my sites using this link, The sites are not able to load the css/js files & images present outside the 'public_html' directory, while it works if I open it via localhost path..
I come from an ubuntu environment, The apache directory structure is quite older on mac! can anyone help me with this..
Thanks
The sites are not able to load the css/js files & images present outside the 'public_html' directory
That is rather the point.
The DocumentRoot is the root of the website. Everything under it is part of the site.
By putting something in the DocumentRoot you are giving it a URL and making it available to be requested over HTTP.
An HTTP server isn't designed to expose every private file on your whole hard disk to the world. That would be awful.
If you want to give a file a URL, then put it in the DocumentRoot (or look at the Alias directives).

Unsure of what to add to hosts file - Apache Subdomain

I'm trying to make a subdomain for my xampp/apache hosted website.
However, whenever I attempt to access the subdomain it gives me an "HTTPS insecure error" and redirects me to the main part of the site. Also, I can still access the main site without any issues at all.
In my 'httpd-vhosts.conf' file, I believe all the entries are correct and the issue lies with my hosts file.
To clarify, this is a website with a premium domain name, (i.e not just a website for local use). Most of the tutorials and guides I can find are only really designed for websites that are used locally only.
Here is my 'httpd-vhosts.conf' file (with my domain name edited out of course):
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName domain.xyz
ServerAlias https://domain.xyz
ErrorLog "logs/domain.xyz-error.log"
CustomLog "logs/domain.xyz-access.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/sub1"
ServerName sub1.domain.xyz
ServerAlias https://sub1.domain.xyz
ErrorLog "logs/sub1.domain.xyz-error.log"
CustomLog "logs/sub1.domain.xyz-access.log" common
</VirtualHost>
The entries I have in my hosts file are (which I'm fairly certain is completely wrong):
127.0.0.1 localhost
127.0.0.1 domain.xyz
127.0.0.1 sub1.domain.xyz

Apache document root and VirtualHost

I'm having some problems with setting up a VirtualHost with Apache on CentOS. I'll try my best to explain what happens.
In our httpd.conf file we had to change the Document root, our base is /var/www/mydomain.com but our files is on /var/www/mydomain.com/store2 and when users goto mydomain.com we want them to come directly to mydomain.com/store2
Main config:
DocumentRoot "/var/www/mydomain.com/store2/"
Directory "/var/www/mydomain.com/store2"
So, I've added an config file inside conf.d named subdomains.conf and this is the information inside
<VirtualHost *:80>
ServerAdmin mail#me.com
DocumentRoot /var/www/mydomain.com/subdomain
ServerName subdomain.mydomain.com
ErrorLog logs/subdomain.mydomain.com
CustomLog logs/subdomain.mydomain.com common
</VirtualHost>
When i restart the httpd service and goto mydomain.com I'm transferred to the virtual host root (/var/www/mydomain.com/subdomain) this also happens when i go to subdomain.mydomain.com. Is there something that I'm missing here? Could there be something with the DNS also? I see that mydomain.com and subdomain.mydomain.com points to the same IP-address.