How to configure different Virtual Hosts based on apache + php_cgi and apache+mod_php? - apache

everybody.
I have a Cent OS 6.6 server with Apache + mod_php site (site1.local). I need to configure second site (site2.local) with php_cgi. So, I created a user, gave him permissions on www-folder, configured site1 as mod_php, created a phpinfo.php. Also, I installed php-cgi,and try to configure virtual hosts, works only first site, on the second site is error:
the requested url /cgi-bin/phpinfo.php was not found onthis server.
That's my configs:
cat /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin webmaster#site1.local
DocumentRoot /var/www/wwwmaster/site1.local
ServerName site1.local
ServerAlias www.site1.local
ErrorLog logs/site1.local-error_log
CustomLog logs/site1.local-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#site2.local
DocumentRoot /var/www/wwwmaster/site2.local
ServerName site2.local
ServerAlias www.site2.local
ScriptAlias /cgi_bin/ /usr/bin/php-cgi/
Action php-cgi /cgi-bin
AddHandler php-cgi php
<Directory /usr/bin/php-cgi>
Allow from all
</Directory>
<Directory "/var/www/wwwmaster/site2.local/">
<FilesMatch "\.php">
SetHandler php-cgi
</FilesMatch>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
ErrorLog logs/site2.local-error_log
CustomLog logs/site2.local-access_log common
</VirtualHost>
What I've done wrong and how can I fix that?

You only have to uncomment the line that says NameVirtualServer *:80 in your apache config file.
If you want virtual server for more than one port, simply put as many NameVirtualServer *:[port number] in the apache config file as you need.

Related

How apache2 can deny connections to a domain which is not hosted

I am hosting website iplocation.io on a cloud server. I found a domain https://chrissloey.com/index.php which opens my website within it.
Now from what I understand, chrissloey.com has pointed it A record to my server ip and my apache2 server is not denying connection to it and allow's to open iplocation.io website content like its own.
I want apache2 to deny connections to any other domain and only allow my own domain to server content.
Attached is apache conf file for iplocation.io
<VirtualHost *:80>
ServerAdmin email#email.com
DocumentRoot /var/www/public_html
ServerName iplocation.io
ServerAlias www.iplocation.io
ErrorLog ${APACHE_LOG_DIR}/apache-error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/public_html>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName iplocation.io
ServerAdmin email#email.com
DocumentRoot /var/www/public_html
SSLEngine on
SSLCertificateFile /path-to-csr
SSLCertificateKeyFile /path-to-key
SSLCertificateChainFile /path-to-ca
<Directory /var/www/public_html>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
</IfModule
Looking at the two comments I think the combination makes most sense:
Configure httpd to respond with redirect (301) to all incoming requests. This could be done on the 'root' host.
Configure a virtualhost listening to your domain only, and this one would serve your real content only.
This will work unless the other site requests your content and then integrates it into their responses. But as you said someone else simply put up a DNS A record.

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 !

Name and IP Virtual Host on Apache

I am trying to direct web traffic for our domain to a Vhost site and our internal web site to separate directory that is only accessible within our private network,i.e 192.168.x.x.
I have modified Vhost configuration on Apache to include a name-based Vhost for the external website and a IP Vhost for the Intranet. No far I have had no luck, Apache does not like it.
Here is my modified Vhost config file.
NameVirtualHost *:80
<Directory "/home/webs">
Options +FollowSymLinks +Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot /home/webs/foo
ServerName www.foo.com
ServerAlias foo.com
LogLevel warn
ErrorLog /home/webs/foo/error.log
CustomLog /home/webs/foo/logs/access.log combined
</VirtualHost>
NameVirtualHost 192.168.0.*:80
<Directory "/home/webs/OffCat">
Options +FollowSymLinks +Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost 192.168.0.*:80>
DocumentRoot /home/webs/OffCat
ServerName 192.168.0.15/OffCat
LogLevel warn
ErrorLog /home/webs/OffCat/logs/error.log
CustomLog /home/webs/OffCat/logs/access.log combined
</VirtualHost>
I would appreciate any help.
Thanks,
Tony Cripps

Windows 7 - XAMPP: vhost keeps redirecting

My hosts file. (Win 7 ultimate)
127.0.0.1 localhost
127.0.0.1 efmm.local
My httpd-vhosts.conf (XAMPP 1.7.3)
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost efmm.local>
DocumentRoot "C:\xampp\htdocs\EFMM"
ServerName efmm.local
ErrorLog "logs/efmm.localhost-error.log"
CustomLog "logs/efmm.localhost-access.log" combined
<Directory "C:\xampp\htdocs\EFMM">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Problem
When I go to efmm.local , the browser redirects to localhost/EFMM.
I also tried <VirtualHost 127.0.0.1:80> instead of <VirtualHost efmm.local>, same result.
Here's how I do it on XP (don't expect it to make any difference in 7)
First, add the virtual host's domain to your HOST (as you did)
I don't put the virtual host webroot under the main htdocs directory. I create a specific webroot next to it, which gives me the following tree:
C:\XAMPP\htdocs
C:\XAMPP\htdocs-seconddomain
C:\XAMPP\htdocs-thirddomain
etc..
So in your case, I would create c:\XAMPP\htdocs-efmm alongside C:\XAMPP\htdocs
Then:
Edit XAMPP's httpd.conf, add and define any Apache options for the new document root, i.e.:
<Directory "C:/XAMPP/htdocs-efmm">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
[any extra apache module instructions you may require]
Order allow,deny
Allow from all
</Directory>
Edit XAMPP's httpd-vhosts.conf, adding the virtual host:
<VirtualHost *:80>
ServerName efmm.local
ServerAlias www.efmm.local
DocumentRoot "C:/XAMPP/htdocs-efmm"
ErrorLog "C:/XAMPP/htdocs-efmm/error.log"
DirectoryIndex index.php index.html index.htm
</VirtualHost>
Restart XAMPP. You may browse your new virtual host now.

How to set up virtual hosts on Apache 2.2

Can anyone direct me to a good tutorial on how to set up virtual hosts using Apache 2.2? Here's my situation:
I have Apache running on my laptop and I want two websites-- one on port 80 and one on port 8089. I want to access each site from the other computer on my network by entering the computer's IP address, such as http://192.168.1.102 and http://192.168.1.102:8089. Yet when I enter the second url, it directs me to the website running on port 80.
Thanks in advance for any help.
First you need to instruct Apache to listen on the ports you need:
Listen 80
Listen 8089
Second you need to tell it what to do with 80 and 8089 traffic:
<VirtualHost *:80>
DocumentRoot /website/site80
ServerName internet.dev
</VirtualHost>
<VirtualHost *:8089>
DocumentRoot /website/site8089
</VirtualHost>
Third you need to "allow" Apache to use those directories:
<Directory "C:/website/site80">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "C:/website/site8089">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Just have 2 virtual hosts defined like this, but with differeing DocumentRoots:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.somecompany.com
DocumentRoot "/docs/dummy-host.somecompany.com"
ServerName dummy-host.somecompany.com
ServerAlias www.dummy-host.somecompany.com
ErrorLog "logs/dummy-host.somecompany.com-error.log"
CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>
<VirtualHost *:8089>
ServerAdmin webmaster#dummy-host.somecompany.com
DocumentRoot "/docs/dummy-host.somecompany.com"
ServerName dummy-host.somecompany.com
ServerAlias www.dummy-host.somecompany.com
ErrorLog "logs/dummy-host.somecompany.com-error.log"
CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>