Try to add a VirtualHost - apache

I have a web server with a website and i want to add another address for pre-production use.
Here the existant:
httpd.conf:
ServerAdmin support#toto.com
ServerName www.toto.com:80
DocumentRoot "/home/tutu/var/www/html"
modules/vhost.conf:
<VirtualHost *:80>
ServerAdmin support#toto.com
ServerName www.toto.com:80
DirectoryIndex index.php
ErrorLog /home/tutu/var/log/httpd/error-mod_log
LogLevel warn
CustomLog /home/tutu/var/log/httpd/access-mod_log common-cookie
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>
And I have tried to add another VirtualHost but the new address not working:
<VirtualHost *:80>
ServerAdmin support#toto.com
ServerName www2.toto.com:80
DirectoryIndex index.php
ErrorLog /home/tutu/var/log/httpd/error-www2_log
LogLevel warn
CustomLog /home/tutu/var/log/httpd/access-www2_log common-cookie
DocumentRoot "/home/tutu/var/www2/html"
</VirtualHost>
The address www2.toto.com is not working.
Have you an idea?
Thanks

Have you added www2.toto.com to DNS?
It's not added to public DNS yet. (But www.toto.com is)
"Not working" is not very specific. Do you get the default Apache web-page for that site or do you not reach the server? If it's the latter, DNS lookup is likely your real problem, not the Apache config.
The Apache-config looks good, but you should not need to specify :80 as the alias port.

Related

(Apache) Forbidden 403 when accessing subdomain

I want to set up the subdomain "shop" on my Apache 2.2 server on Windows/XAMPP and it redirects to "index.html" if I enter "shop.localhost" as the URL but once I try to connect via my domain "sv443.net" it redirects to my document root ("/index.html" instead of "/shop/index.html"). Connecting to "sv443.net/shop/" works fine though and even redirects to "index.html".
I'm using Cloudflare to handle the DNS stuff and added these records (I cut off the IP address part):
This is my httpd-vhosts.conf:
NameVirtualHost localhost:80
<VirtualHost localhost:80>
ServerName localhost
ServerAdmin sven.fehler#web.de
DocumentRoot "c:/users/sv443/desktop/mamp htdocs"
<Directory "c:/users/sv443/desktop/mamp htdocs">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost shop.localhost:80>
ServerName shop.localhost
ServerAdmin sven.fehler#web.de
DocumentRoot "c:/users/sv443/desktop/mamp htdocs/shop"
<Directory "c:/users/sv443/desktop/mamp htdocs/shop">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
And this is my hosts.dat:
(only comments)
2.205.169.73 sv443.net
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost shop.localhost
Also I added this .htaccess file to the shop directory to redirect to the index.html if a 403 or 404 is encountered - removing this file doesn't fix my problem:
ErrorDocument 403 /shop/index.html
ErrorDocument 404 /shop/index.html
If someone tries to connect I get this error message in the Apache error.log:
AH01630: client denied by server configuration: C:/Users/Sv443/Desktop/MAMP htdocs/shop/.html
Thanks for any help!
If you can get content by explicitly specifying "/index.html" but not with "/", you should add DirectoryIndex index.html in your configuration, after loading mod_dir. This will define the default file to look for when it is not specified.
For your VirtualHost:
<VirtualHost *:80>
ServerName localhost
ServerAlias www.example.com
ServerAlias example.com
LogLevel debug
CustomLog "logs/example_access_log" combined
ErrorLog "logs/example_error_log"
[... REST OF CONFIGURATION ...]
</VirtualHost>
<VirtualHost *:80>
ServerName shop.localhost
ServerAlias shop.example.com
LogLevel debug
CustomLog "logs/shop_access_log" combined
ErrorLog "logs/shop_error_log"
[... REST OF CONFIGURATION ...]
</VirtualHost>
Apache decides which VirtualHost to use for the request based on the domain in the request. If it does not find a match, it uses the first one in the file (here localhost). Therefore you are not pointing to your "shop" sub-domain, unless you specify it in the VirtualHost for it, via ServerAlias ....

Virtual Hosts on WAMP causing 403 forbidden on localhost... other aliases still work

I just realized that nothing else on WAMP is accessible unless it's under the virtual host alias. For example: if I name my vHost 'mysite.dev', I can only access mysite.dev and everything else gives a 403 forbidden error. If I add a vHost called anothersite.dev in addition to mysite.dev, only those sites can be accessed. The only thing under localhost that I can access is PHPMyAdmin. I have uncommented the line that includes vHosts.conf in the Apache httpd.conf file. This problem does not happen until I modify the vHosts.conf file. Here is the config for the other files:
vHosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "W:/wamp/www/mysite"
ServerName mysite.dev
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
Windows hosts file:
127.0.0.1 localhost
127.0.0.1 mysite.dev
Ok first, the first 2 VHOST definitions in the httpd-vhost.conf file (vhost and vhost2) are examples, supplied by Apache, to help you get started and of course point to folders that do not exist so and should be removed.
Second When you create a Virtual Host you should include the access privilages for the VHOST in a <Directory....> group.
Third, you should always create a VHOST for localhost as once VHOSTs are created Apache ignores the localhost definition in httpd.conf
So your httpd-vhost.conf file should look like this
# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "W:/wamp/www"
ServerName localhost
<Directory "W:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "W:/wamp/www/mysite"
ServerName mysite.dev
ErrorLog "logs/mysite.dev-error.log"
CustomLog "logs/mysite.dev-access.log" common
<Directory "W:/wamp/www/mysite">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
Once you have done this, you now need to edit your c:\windows\system32\drivers\etc\hosts file to look like this. You need to have admin privilages to edit this file, also some anti virus suites also protect this file, so you may need to stop that protection temporarily in order to amend this file.
127.0.0.1 localhost
127.0.0.1 mysite.dev
::1 localhost
::1 mysite.dev
Then restart the dnscache to pick up these changes, from a command line also started with admin privilages.
net stop dnscache
net start dnscache
This post may help you understand more about Virtual Hosts

apache virtual host setting is not working

I am trying to setup the virtual host for apache on Mac.
Here is my virtual host setting in /etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin localhost
DocumentRoot "/Users/Ivy/Sites/Symfony"
ServerName symfony.dev
ErrorLog "/private/var/log/apache2/symfony.dev-error_log"
CustomLog "/private/var/log/apache2/symfony.dev-access_log" common
<Directory "/Users/Ivy/Sites/Symfony">
options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Additionally, editing the file in /etc/hosts
127.0.0.1 symfony.dev
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
192.168.43.168 matrixdemo.squiz.net
But when i go to symfony.dev in the web browser, it cannot connect to. could someone help me on that?
Note: tried to restart the apache several times
Try this it will work
NameVirtualHost *:80
#Do not forget to include server name and server alias in host file
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "D:\Local server\htdocs\localhost"
CustomLog logs/localhost.access.log combined
ErrorLog logs/localhost.error.log
</VirtualHost>
You could make it
<VirtualHost symfony.dev>
ServerName symfony.dev
ServerAdmin your.mail#whatever.com
DocumentRoot "/Users/Ivy/Sites/Symfony/web"
ErrorLog "/private/var/log/apache2/symfony.dev-error_log"
CustomLog "/private/var/log/apache2/symfony.dev-access_log" combined
<Directory "/Users/Ivy/Sites/Symfony/web">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
=> "Directory" instructions should be for your root-symfony-directory/web folder, as your document root.
=> What's this "common" behind your Custom Log directory ? Did you mean "combined" ?
=> In symfony2, you need to make sure that all the requests are directed to you bootstrap - this is where rewrite engine comes in. Oh, But I see this bit has moved into the .htaccess in earlier versions of symfony :o So no need for it here. Note that you have configuration instructions for apache and symfony2 here
There is much more science behind this, but these are the parameters I use for my setup. For more info, read the docs !

Looking to redirect path /blog to another server using Apache

I want to host my blog on it's own server, but have the URL be at mysite.com/blog
Should I do this using mod_proxy or an apache redirect, and how would I set this up on apache?
My first pass attempt looks like so in the vhost file, but failed:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /blog http://blog.server's.ip.address/
ProxyPassReverse /blog http://blog.server's.ip.address/
ServerAdmin me#myemail.com
ServerName mysite.com
DocumentRoot /var/www
<Directory /var/www>
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
With this is place I get the following error when restarting apache:
Restarting web server apache2 /sbin/start-stop-daemon: warning: failed to kill 11306: Operation not permitted
[fail]
The apache2 configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!
mod_proxy needs to be enabled before working >_<
Once I enabled it my config worked as expected.
a2enmod proxy_http
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /blog http://server4.hostinger.co.uk.ip.31.170.164.19/
ProxyPassReverse /blog http://server4.hostinger.co.uk.ip.31.170.164.19/
ServerAdmin http://webmail.hostinger.co.uk
ServerName armukul.com.ip address 31.170.164.123 domain ip ("A" DNS record) to this IP: 31.170.164.123
DocumentRoot /var/www.armukul.com/home/u311366417
<Directory /var/www>armukul.com
Order allow,deny
allow from all
</Directory>www>armukul.net
</Directory>www>facebook.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>[][1]
[1]: http://armukul.com/home

Two apps on Apache server with URI

I need to install a server with Apache 2.2 on Linux and I need to do two VirtualHosts differentiated by URI.
But with only one domain name and one ip address. And I can't use Alias.
I tried something like that but that doesn't work :
<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName localhost/app1
ServerAlias www.localhost/app1
<Directory /var/www/app1>
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/app2
ServerName localhost/app2
ServerAlias www.localhost/app2
<Directory /var/www/app2>
Allow from all
</Directory>
</VirtualHost>
Thank you to the first answer here, it's working : https://serverfault.com/questions/588841/two-apps-on-apache-server-with-uri
I put the answer here if one day the link doesn't work :
What you could do is set up a reverse proxy to different virtual hosts listening only on loopback.
You would get in your www.localhost virtualhost:
<VirtualHost *:80>
DocumentRoot /var/www/
ServerName localhost
ServerAlias www.localhost
ProxyPassReverse /app1/ http://webapp1.local/
ProxyPassReverse /app2/ http://webapp2.local/
</Virtualhost>
And create two virtualhosts for the apps:
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/app1
ServerName webapp1.local
<Directory /var/www/app1>
Allow from all
</Directory>
</Virtualhost>
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/app2
ServerName webapp2.local
<Directory /var/www/app2>
Allow from all
</Directory>
</Virtualhost>
Make sure to add webapp1.local and webapp2.local to your /etc/hosts file.
Since you have only a single domain name and only a single ip address available there is no means for the apache server to distinguish which host is meant. Therefore there is noo sense in defining VirtualHosts here.
However you certainly can place two apps in separate folders inside your DocumentRoot:
ServerName whatever-your-domain.is
DocumentRoot /var/www
<Directory /var/www/app1>
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/app2>
Order allow,deny
Allow from all
</Directory>
Then you'd call those apps by their paths:
apps1: http://whatever-your-domain.is/app1
apps2: http://whatever-your-domain.is/app2
Don't forget to take care of requests to the "main folder" of that single host: /var/www which can be reached by http://whatever-your-domain.is/