I'm currently migrating a bunch of websites to amazon ec2 (running on the Amazon Linux AMI), and am having difficulties getting Apache's VirtualHost configuration to work.
Here's what my httpd.conf file looks like:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /home/sites/example.com/
<Directory /home/sites/example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/example.com.error.log
LogLevel warn
CustomLog /var/log/httpd/example.com.access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /home/sites/blog.example.com/
<Directory /home/sites/blog.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/blog.example.com.error.log
LogLevel warn
CustomLog /var/log/httpd/blog.example.com.access.log combined
</VirtualHost>
Here's the result of httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 example.com (/etc/httpd/conf.d/ssl.conf:74)
*:80 is a NameVirtualHost
default server example.com (/etc/httpd/conf/httpd.conf:1012)
port 80 namevhost example.com (/etc/httpd/conf/httpd.conf:1012)
port 80 namevhost blog.example.com (/etc/httpd/conf/httpd.conf:1029)
Syntax OK
However, if I attempt to go to blog.example.com, I get a ERR_NAME_NOT_RESOLVED response.
If I change the first VirtualHost definition to blog.example.com, I can load the blog.example.com site, so both sites are working, leading me to suspect I either have configured something wrong in VirtualHost, or on the end of my domain registrar.
My issue was that I had the example.com domain before the blog.example.com domain, meaning everything just went to example.com. Order matters!
Related
I am trying to run site my.com locally on XAMPP's apache server. Here my configurations in httpd-vhosts.conf file in the path ...\XAMPP\apache\conf\extra:
<VirtualHost *:80>
DocumentRoot "D:/IDEs/XAMPP/htdocs"
ServerName localhost
<Directory "D:/IDEs/XAMPP/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Also, I remembered to add two lines in the hosts file, with is located in C:\Windows\System32\drivers\etc:
127.0.0.1 localhost
127.0.0.1 my.com
However, when I enter via link 'my.com' with enabled apache server, I've got only page with folder directories, which are in htdocs XAMPP's folder.
I have checked a lot of videos and stackoverflow questions, but nothing helped.
I would be pleased if you could help me with solving this issue.
first you should arrange directories on httpd.conf
example:
<Directory "C:/SERVER~1/web/site1">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "C:/SERVER~1/web/site2">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and then arrange vhosts.conf like this
example :
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName www.site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
After five days-night of reading, searching, trying, I finnally fould the solution and done it in some steps:
First of all, forget about every file, and concentrate on the httpd-ssl.conf which is located in D:\IDEs\XAMPP\apache\conf\extra.
Second:
find the line "SSL Virtual Host Context" which has been commented. And below, find the line <VirtualHost _default_:443>.or simmilar. Then change it to <VirtualHost *:443>.
Third, change document root to the path of xampp's htdocs, for example, "D:/XAMPP/htdocs". Also, change ServerName from www.example.com:443 or similar, to localhost.
Here we done.
And Finally, after line </VirtualHost>, insert code
<VirtualHost *:443>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Require all granted
</Directory>
</VirtualHost>
Change Document Root and Directory paths to your website location. And Servername to your server name.
RESTART APACHE
it works for me.
I also understood than some website uses SSL on localhost while the others not.
SO if you have exception like Apache/2.4.37 (Win32) OpenSSL/1.0.2p PHP/7.0.33 Server at my.com Port 443 you shold add your virtualhost configs into httpd-ssl.conf file.
If you got like ... Port 80 add yourl virtualhost configs into httpd-vhosts.conf
I tried to install Gitlab on my webserver. I configured everything appropriately. This is a scheme of what I am trying to achieve:
example.com:80 (default host)
vhost1.example.com:80 (a virtual host)
example.com:8080 (gitlab)
So what happens is this: I can open example.com and vhost1.example.com normally. If gitlab-ctl is stopped, I get a "Website not available"-error if I try to open example.com:8080 (as expected). When I start gitlab and try to open example.com:8080 again, it shows me the gitlab-error "502 Error GitLab is taking too much time to respond", but only the first time I load this page, as soon as I refresh or try it again in a new tab, it redirects my request always to example.com, although I request the page with ":8080" at the end.
I have access to gitlab with http://x.x.x.x:8080. This works but I'm forced to configure http://example.com:8080
System:
Debian Wheezy
Apache/2.2.22
gitlab-ce_8.4.1-ce (includes nginx)
Here are my configuration files:
/etc/apache2/sites-available/example.com
<VirtualHost *:80>
ServerAdmin mail#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error_example.com.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/apache2/sites-available/vhost1.example.com
<VirtualHost *:80>
ServerAdmin mail#example.com
ServerName vhost1.example.com
ServerAlias www.vhost1.example.com
DocumentRoot /var/www/vhost1.example.com
ErrorLog ${APACHE_LOG_DIR}/error_vhost1.example.com.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/vhost1.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/apache2/ports.conf (only changes)
NameVirtualHost *:80
Listen x.x.x.x:80
<IfModule mod_ssl.c>
Listen x.x.x.x:443
</IfModule>
<IfModule mod_gnutls.c>
Listen x.x.x.x:443
</IfModule>
/etc/gitlab/gitlab.rb (only changes)
external_url 'http://example.com:8080'
unicorn['port'] = 8081
nginx['listen_addresses'] = ["x.x.x.x"]
nginx['listen_port'] = 8080
netstat -napl | grep :80
tcp 0 0 x.x.x.x:8080 0.0.0.0:* LISTEN 19037/nginx
tcp 0 0 x.x.x.x:80 0.0.0.0:* LISTEN 18280/apache2
tcp 0 0 127.0.0.1:8081 0.0.0.0:* LISTEN 19110/config.ru
I would really appreciate every hint. If you need further information just ask.
After some tinkering I found a solution that worked for me. If someone has the same problem here you go:
Apache was configured correctly, so the configuration stays as is.
/etc/apache2/sites-available/example.com
<VirtualHost *:80>
ServerAdmin mail#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error_example.com.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/apache2/sites-available/vhost1.example.com
<VirtualHost *:80>
ServerAdmin mail#example.com
ServerName vhost1.example.com
ServerAlias www.vhost1.example.com
DocumentRoot /var/www/vhost1.example.com
ErrorLog ${APACHE_LOG_DIR}/error_vhost1.example.com.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/vhost1.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/apache2/ports.conf (only changes)
NameVirtualHost *:80
Listen x.x.x.x:80
<IfModule mod_ssl.c>
Listen x.x.x.x:443
</IfModule>
<IfModule mod_gnutls.c>
Listen x.x.x.x:443
</IfModule>
The problem existed because of the gitlab.rb configuration. The solution is not to change too much. Only these two lines are needed for gitlab to work:
/etc/gitlab/gitlab.rb (only changes)
external_url 'http://git.example.com:8080'
unicorn['port'] = 8081
If you're not planning to run Gitlab on Port 8080, you don't have to assign a new port for unicorn. Do not forget to run 'gitlab-ctl reconfigure' after the changes.
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
I have defined two VirtualHosts on Apache, and the problem is, one of them overrides the other one. i.e. when I try to reach the second address, the first one shows up.
Here is my first config:
ServerName www.example1.com
DocumentRoot /server/sites/example1
<VirtualHost *:80>
ServerAdmin admin#example1.com
DocumentRoot /server/sites/example1
ServerAlias example1.com
<Directory /server/sites/example1/>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And the second:
ServerName www.example2.tv
DocumentRoot /server/sites/tv/public/
<VirtualHost *:80>
ServerAdmin admin#example2.tv
DocumentRoot /server/sites/tv/public
<Directory /srver/sites/tv/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
When I load www.example2.tv, it still shows www.example1.com content.
example1 is written in PHP and example2 is Ruby on Rails.
You need to have the ServerName directive inside the VirtualHost configuration i.e.:
<VirtualHost *:80>
ServerName www.example2.tv
ServerAdmin admin#example2.tv
DocumentRoot /server/sites/tv/public
<Directory /server/sites/tv/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
You can examine your configured VirtualHosts using apachectl -S - this will print a list of all the configured VirtualHosts and their corresponding config files
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>