Apache 2 VHost - www.domain.com works but domain.com goes to registrar - apache

I am using the following VHOST:
<VirtualHost *:80>
#Basic setup
ServerAdmin administrator#mydomain.com
ServerName www.mydomain.com
ServerAlias mydomain.com
<Directory /home/mydomain/public_html/mydomain.com/mydomain/apache/>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
ErrorLog /home/mydomain/public_html/mydomain.com/logs/apache_error.log
CustomLog /home/mydomain/public_html/mydomain.com/logs/apache_access.log combined
WSGIDaemonProcess mydomain.com user=www-data group=www-data threads=20 processes=2
WSGIProcessGroup mydomain.com
WSGIScriptAlias / /home/mydomain/public_html/mydomain.com/mydomain/apache/mydomain.wsgi
</VirtualHost>
It's working fine when I visit www.mydomain.com, but mydomain.com is taking me to my domain registrars holding page (I am using their nameservers for simplicity.) Is this a problem with my vhost file or something I need to configure with the registrar?

Add mydomain.com A record in DNS
Add www.mydomain.com as cname in DNS
In vhost configuration change the entry like this:
ServerName mydomain.com
ServerAlias www.mydomain.com
It will work.

Related

Appache virtualhost and proxy

I am trying to redirect a virtualhost to a spefcific ip, in A docker network in my case.
I am on a raspberrypi4 with archlinux.
So, here is my config file, but it do not work, this redirect in my default vhost in local :
<VirtualHost *:80>
#ServerAdmin webmaster#mysite.com
#DocumentRoot "/srv/http/mysite.com"
ServerName mysite.com
ServerAlias mysite.com
ErrorLog "/var/log/httpd/mysite.com-error_log"
CustomLog "/var/log/httpd/mysite.com-access_log" common
ProxyPreserveHost On
ProxyPass "/" "http://172.19.0.5/"
ProxyPassReverse "/" "http://172.19.0.5/"
# <Directory "/srv/http/http/mysite.com">
# Require all granted
# </Directory>
</VirtualHost>
does anybody can help me to fix that ?? :/

Apache2 VirtualHost SSL config issues

Debian 10 / Apache2 -
GOAL: redirect all web traffic to VPS server to SSL. I have 2 sites hosted: bjmurrey.com and nextcloud.bjmurrey.com. I have 1 IP address.
PROBLEM: I can't for the life of me find a way to make this work. I have tried 1000 suggestions posted here and elsewhere with no success. The closest I get is everything redirects to https://bjmurrey.com when typing in nextcloud.bjmurrey.com. I am also a novice at this so please be kind.
I have a default.conf that looks like this:
<VirtualHost *:80>
ServerName www.bjmurrey.com
ServerAlias bjmurrey.com
DocumentRoot /var/www/blog
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Redirect permanent / https://bjmurrey.com/
</VirtualHost>
<VirtualHost *:80>
ServerName nextcloud.bjmurrey.com
DocumentRoot /var/www/nextcloud
ServerAlias nextcloud.bjmurrey.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Redirect permanent / https://nextcloud.bjmurrey.com/
</VirtualHost>
I have a default-ssl.conf that looks like this:
<VirtualHost bjmurrey.com:443>
ServerName bjmurrey.com
ServerAlias www.bjmurrey.com
DocumentRoot /var/www/blog
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/bjmurrey.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/bjmurrey.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost nextcloud.bjmurrey.com:443>
ServerName nextcloud.bjmurrey.com
DocumentRoot /var/www/nextcloud
ServerAlias nextcloud.bjmurrey.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/nextcloud.bjmurrey.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/nextcloud.bjmurrey.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
bjmurrey.com is in var/www/blog and nextcloud.bjmurrey.com in the var/www/nextcloud directories.
I have my DNS records www and nextcloud both pointed to same IP. I only have 1 IP available. This is a very low traffic site.
I have done all kinds of things like just have the default virtual host redirect to only nextcloud and removed all mention of the www site and it still redirects to bjmurrey.com, or redirects with an SSL error saying that nextcloud can't be loaded because the ssl is for bjmurrey.com only. As you can see I have made certs with letsencrypt for both bjmurrey.com and nextcloud.bjmurrey.com.
I'm about to yank all my hair out in frustration, so I know I've tapped out all my knowledge here. Help!
I have retested with http and is working for me.
Both addresses mydomain.myhost.example.com and myhost.example.com resolve to the same IP.
This is my configuration file
ServerName example.com
<VirtualHost *:80>
ServerName mydomain.myhost.example.com
DocumentRoot /var/www/mydomain
</VirtualHost>
<VirtualHost *:80>
ServerName myhost.example.com
DocumentRoot /var/www/myhost
</VirtualHost>
Tested in Ubuntu 20.04.1, Apache 2.4

How to make an redirectSSL in the vhost

I get slightly crazy :)
I have a domain example.com and I have a SSL certificate for www.example.com
The example.com refers to the IP address of the server (it is an EC2 instance).
In the vhost.conf of the Server I have the following entries
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName www.example.com
DocumentRoot /var/www/vhosts/example-wp
SSLEngine On
...
</VirtualHost>
I took the information from the apache wiki.
https://wiki.apache.org/httpd/RedirectSSL
Thanks for helping
Tristan
You already have the necessary directives listed to perform the redirect. You also need to tell the vhost file where your certificate and key for the certificate exist. You also need to say whether or not a directory the user browses to is to load SSL. Please see a full example configuration file below.
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
Redirect / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster#local
DocumentRoot /path/to/web/content
DirectoryIndex index.php index.html
ErrorLog logs/error_log
CustomLog logs/access combined
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/apache2/ssl.crt/certfile.cer
SSLCertificateKeyFile /etc/apache2/ssl.key/keyfile.key
<Directory "/path/to/web/content/">
Options None
AllowOverride None
Order allow,deny
Allow from all
SSLRequireSSL
</Directory>
</VirtualHost>

Apache VirtualHost - domain name

I bought a domain name, one with ".fr" and the other one with ".com"
Now I want to redirect my domaine name to a server running on the port 4000.
For that I used virualhost:
<VirtualHost *:80>
ServerName http://www.example.fr
ServerAlias example.fr
ProxyRequests Off
ProxyVia On
ProxyPass / http://localhost:4000/
ProxyPassReverse / http://localhost:4000/
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
It works fine when I access ".com" but doesn't work with the ".fr".
Any idea ? thx
Change ServerName and ServerAlias to:
ServerName example.fr
ServerAlias www.example.fr example.com www.example.com

Creating Wildcard Sub Domain Using Apache VirtualHost

I want to have this situation :
if user request using this URL : example.com or www.example.com,
user will see index.php in this directory /home/admin1/public_html/
but when user request using other sub domain (wildcard) for example : freediscount.example.com, user will see index.php in this path : /home/admin1/public_html/userweb/freediscount.example.com
technical support on my hosting suggest me to use this method : http://www.wiredstudios.com/php-programming/setting-up-wildcard-dns-for-subdomains-on-cpanel.html
based on that tutorial, the PHP has a new job... to redirect on specific folder when user request with sub domain. I don't like this method. for me, it would be better if Apache can handle this.
nearly close to what I need is this method : Virtualhost For Wildcard Subdomain and Static Subdomain
but, I have a problem with VirtualHost setting, how to create VirtualHost correctly for that situation?
here's what I've done but didn't work :
## I think this one is for www or without www, automatically generated with WHM
<VirtualHost xx.xx.xx.xx:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/admin1/public_html
</VirtualHost>
## Here's what I'm trying to add
<VirtualHost xx.xx.xx.xx:80>
ServerName example.com
DocumentRoot /home/admin1/public_html/userweb/*
</VirtualHost>
Wildcard sub-domains are definitely possible using Apache virtual hosts.
I had basically the same requirements and managed to get it working with Apache's mod_vhost_alias.so module. Try this in your http-vhosts.conf file:
DocumentRoot "/home/admin1/public_html/userweb/"
<Directory "/home/admin1/public_html/userweb/">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName www.example.com
</VirtualHost>
<VirtualHost *:80>
VirtualDocumentRoot /home/admin1/public_html/userweb/%1.example.com/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName example.com
</VirtualHost>
Note that I haven't tested this, but it's pretty close to the solution that worked for me.
Full details of my solution are here:
http://www.calcatraz.com/blog/wildcard-subdomains-in-apache-1422
Try with this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName www.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/userweb/freediscount.example.com
ServerName other.example.com
ServerAlias *.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName example.com
</VirtualHost>
Order of virtual hosts & their specificity matters.