Resolving virtual hosts apache 2 - linux

I'm trying to setup my apache server to access certain folders when I type addresses like test1.example.com test2.example.com etc.
So far I read and did many things but with no success yet. I'll be very thankful if you can help me.
So to start I'm using ubuntu 12.10 as my desktop and I've set up apache server there. I've added example.com in hosts resolving to 127.0.0.1. So far no problems. I've enable vhost_alias and mod_rewrite in apache and I'm using this for my virtual server
NameVirtualHost *:80
UseCanonicalName Off
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?([^\.]+).example.com$
RewriteRule ^(.*) $1 [F]
VirtualDocumentRoot /home/example/server/projects/%1/public_html
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /home/radoslav/server/projects>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
#log file for this server
CustomLog /var/log/apache2/example.com.log combined
</VirtualHost>
But when I open test.example.com it says that browser can find test.example.com, no matter that I have this directory in the path specified. Just to clear things up apache have permissions to read this directory so it's not this. When I ping example.com from console I get ping but if I ping test.example.com I get error that can not find host. As you can see obviously it's not resolving the adress no matter that I've setup everything correcly.
Any help guys?

You need to add test.example.com and any other hostnames you want to use in the host file. The host file does not supports wildcard.

Related

Running Traefik docker-proxy behind an apache server, redirecting/proxying some of the requests (or vice versa)

I have a Traefik-2 docker-compose-setup for dev (and one similar for prod) with multiple docker-compose projects containing multiple dc-images, each can be reached locally like this: https://docker-app1.docker-doamin1.loc, incl. HTTPS/SSL-Certs; "dns" via /etc/hosts.
This works like a charm, when the traefik-container is running and the apache is not (port conflict otherwise)
I also have some projects that can be run directly on a local apache (on ubuntu/debian) with configurations in /etc/apache2/sites-available/ like this:
<VirtualHost *:80>
ServerName apache-app1.apache-domain1.loc
DocumentRoot /path-to/apache-app1.apache-domain1.loc/public
<Directory /path-to/apache-app1.apache-domain1.loc/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
Fallbackresource /index.php
</Directory>
DirectoryIndex index.php index.html
</VirtualHost>
But only if the apache is running and the docker-traefik container ist not, again because of the conflicting 80/443
I need (or want) both Versions to run simultaneously.
My idea was to run the docker-traefik container on different ports (20080/20443) and redirect/ProxyPass from apache to that docker-proxy-container (the other way round would be okay too)
I tried (e.g.)this:
<VirtualHost *:443>
ProxyPreserveHost On
ProxyRequests Off
ServerName docker-app1.docker-doamin1.loc
ServerAlias www.https://docker-app1.docker-doamin1.loc
ProxyPass / https://docker-app1.docker-doamin1.loc:20443/
ProxyPassReverse / https://docker-app1.docker-doamin1.loc:20443/
</VirtualHost>
having
127.0.1.1 docker-app1.docker-doamin1.loc
in my /etc/hosts.
But it does not work. And it would be better in each case to have wildcards redirected like this: *.docker-doamin1.loc.
For now all of this is for a local dev environment, so security is not that relevant.
It would be great, if someone had some hints here.

How to redirect wildcard subdomain to my domain

I would like to redirect wildcard subdomain to my actual domain.
like this (I already have error.example.com)
dsfas.example.com -> error.example.com
but I could not do this after hours of searching. Is there a solution to this.
I am using apache
You can do this by creating a “catch-all” Apache configuration and redirecting to the domain you specify.
Create an Apache configuration file with a name like zzz-catchall.conf (so that it’s the last file alphabetically in the directory) and paste this into the file:
<VirtualHost *:80>
ServerAdmin none#noaddy.net
DocumentRoot /var/www/catch/public
ServerName catch.example.com
ServerAlias *.example.com *.*
DirectoryIndex index.php index.html
ErrorLog ${APACHE_LOG_DIR}/catch-error.log
CustomLog ${APACHE_LOG_DIR}/catch-access.log combined
<Directory /var/www/catch/public>
Options FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
Be sure to change the domain names and directories accordingly.
In the /var/www/catch/public (or whatever) directory, you can set up a redirect a number of ways, but .htaccess would be simple enough:
Redirect 301 / https://error.example.com/
Ensure the virtual host configuration file is enabled, and reload Apache. That should get you going 👍🏻

Apache2 Ubuntu config showing google search

I have configured my fresh installed apache. When I am trying to put local.myproject in the browser it starts searching on google. Like the link was not working. Could somebody please tell me what happens? I tried to restart apache and reload the conf files.
sites-availabe/myproject.conf:
ServerName local.myproject
DirectoryIndex index.php index.html
DocumentRoot /home/programmer/NetBeansProjects/myproject/public
ErrorLog ${APACHE_LOG_DIR}/error_1.log
CustomLog ${APACHE_LOG_DIR}/access_1.log combined
<Directory /home/programmer/NetBeansProjects/myproject/public>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
/etc/hosts file:
127.0.0.1 localhost
127.0.1.1 computer
127.0.0.1 local.myproject
Restart your Apache server by:
sudo service apache2 restart
OR
Check error log:
ls /var/log/apache2/error-YOURDOMAINNAME.log
You can check what you missed by check every steps here.

Can linux host mutiple websites with one domain's different third domains?

I recently made some projects on raspberry pi with linux Debian Jessie, and I am interested in porting forward websites hosted on raspberry pi to a domain I owned.
From what I learned, it is possible to make each individual website on raspberry link with configured port according to apache , for example /home/pi/html/website01 -> port 11235 website02 -> 11236 so that I can browse the websites in private network. However, the domain I have is managed by godaddy, they provide the Chain without port, so that I can't redirect one of my third level domain(ex dashboard.domain.com to my dynamic dns hostname xx.dtdns.net with the port.
Is there any possible way or idea to get it work? I am lack of knowledge of nameserver, but I have an idea that using vpn or vps to map users to my private network instead of godaddy domain manager. I have alreay built the openvpn with cert and pptp vpn on my raspberrypi. Is it possible or what's next step?
Thanks, please give me some idea.
One solution would be to use Virtual Hosting in Apache on your Raspberry. Install Apache2 on PI with:
apt-get install apache2
Create a new conf file in /etc/apache2/sites-available or use an existing one. Add the ports for different site directories:
<VirtualHost *:11235>
DocumentRoot /var/www/w1
<Directory /var/www/w1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:11236>
DocumentRoot /var/www/w2
<Directory /var/www/w2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
and then set Apache tolisten on the ports in the /etc/apache2/ports.conf file:
Listen 11235
Listen 11236
Restart the Apache service. You should now be able to browse both ports using the same ip address. If your ip was 111.111.111.111 then w1 directory on 111.111.111.111:11235 and 111.111.111.111:11236.
If your domain is pointing to a IP, you can use different hostnames without making change to DNS. If you domain was mydomain.com, you could instead add new virtual host names with:
<VirtualHost *:80>
ServerName w1.mydomain.com
DocumentRoot /var/www/w1
<Directory /var/www/w1>
Options +Includes -Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName w2.mydomain.com
DocumentRoot /var/www/w2
<Directory /var/www/w2>
Options +Includes -Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

Error setting up multiple vhosts with Apache2 on Mint 15

I just installed Apache2 on mint 15. I am able to see the localhost and so decided to add virtual hosts for my projects.
I have added the hostnames at /etc/hosts
127.0.0.1 eclipse
I also added vhost details at /etc/apache2/site-avaliable:
<VirtualHost *:80>
ServerAdmin webmaster#eclipse
ServerName eclipse
ServerAlias www.eclipse
# Indexes+Document Root
DirectoryIndex index.html index.php
DocumentRoot /home/cygnus/Dropbox/Workspace_Eclipse
#logfiles
ErrorLog /var/log/apache2/eclipse-error.log
CustomLog /var/log/apache2/eclipse-access.log combined
<Directory /home/cygnus/Dropbox/Workspace_Eclipse>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
</VirtualHost>
I activated the vhost using:
sudo a2ensite example.com
Also added following to /etc/apache2/httpd.conf
ServerName localhost
ServerName eclipse
After all the work I checked:
http://localhost - works OK.
http://eclipse - gives 403 error.
Do I need to do anything more to add vhost in linux? Did I miss or mess up some step?
Any help is appreciated - Thanks in advance :)
Update:
I tried changing the DocumentRoot to "/var/www/test/" - this works
but I need it to work at home level.
I used chown and chgrp to set owner and group to both www-data and root - neither worked.
It's probably the <Directory> container:
<Directory /home/cygnus/Dropbox/Workspace_Eclipse>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
Are you sure your requests are actually coming from 127.0.0.1? What's the remote_addr IP that shows up in the logs? To verify, try removing the Deny from all line and see if you can access it.
Found my answer here
All I was missing was: chmod -R 755 /home/cygnus/Dropbox/*

Resources