I try to configure virtual hosts. All I do step by step like here
My config:
root#ubuntu:/etc/apache2/sites-available# cat mmv.com.conf
# create new for [mmv.com]
<VirtualHost *:80>
ServerName www.mmv.com
ServerAdmin webmaster#virtual.host
DocumentRoot /var/www/mmv.com
ErrorLog /var/log/apache2/mmv.com.error.log
CustomLog /var/log/apache2/mmv.com.access.log combined
LogLevel warn
</VirtualHost>
My index.html in root folder
cat /var/www/mmv.com/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Virtual Host Test Page
</div>
</body>
</html>
My /etc/hosts
127.0.0.1 localhost
127.0.1.1 ubuntu
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.125.137 www.mmv.com
Looks like all I did right but if I try to open site www.mmv.com and I see default apache page.
Help me to find where I did mistake.
Thanks!
Try this:
ln -s /etc/apache2/sites-available/mmv.com.conf /etc/apache2/sites-enabled
Then restart your apache server.
Stupid guess: the file is in sites-available, but was it enabled?
If you have debian you can use a2ensite mmv.com, otherwise you have to use ln -s as Kiani advised in ^^^.
I found a solution! That right config:
VirtualHost 192.168.125.138:80>
ServerName www.mmv.com
ServerAlias mmv.com *.mmv.com
ServerAdmin webmaster#mmv.com
DocumentRoot /var/www/www.mmv.com
ErrorLog /var/log/apache2/mmv.com.error.log
CustomLog /var/log/apache2/mmv.com.access.log combined
</VirtualHost>
And in file /etc/hosts have to be this:
192.168.125.138 mmv.com www.mmv.com
Related
EDIT: I HAVE SINCE FIXED IT BY ALLOWING PORT 80 THROUGH UFW (sudo ufw allow 80)(sudo service ufw status verbose)
I've been fiddling with this for a while and can't figure it out, the issue I'm having is that the dev subdomain outputs files of the main server, you can find relevant info attached below.
I have changed my domain to abc.com, and changed the IP.
Yes, the config is enabled, and Apache has been restarted, but I'm still being served the file /var/www/abc.com/public/index.php rather than /var/www/dev.abc.com/public/index.php.
At this point, I've given up due to my lack of Linux + Apache knowledge.
Zone file:
$ORIGIN abc.com.
$TTL 1800
abc.com. IN SOA ns1.digitalocean.com. hostmaster.abc.com. 1467393676 10800 3600 604800 1800
abc.com. 1800 IN NS ada.ns.cloudflare.com.
abc.com. 1800 IN NS neil.ns.cloudflare.com.
abc.com. 1800 IN A XXX.XXX.XXX.XXX
www.abc.com. 1800 IN CNAME abc.com.
dev.abc.com. 1800 IN A XXX.XXX.XXX.XXX
/etc/hosts:
127.0.1.1 ubuntu-512mb-nyc2-01 ubuntu-512mb-nyc2-01
127.0.0.1 localhost
XXX.XXX.XXX.XXX abc.com
XXX.XXX.XXX.XXX www.abc.com
XXX.XXX.XXX.XXX dev.abc.com
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
abc.com.conf:
NameVirtualHost XXX.XXX.XXX.XXX:80
ServerName abc.com
<VirtualHost XXX.XXX.XXX.XXX:80>
ServerName abc.com
ServerAlias www.abc.com
DocumentRoot /var/www/abc.com/public/
</VirtualHost>
<VirtualHost XXX.XXX.XXX.XXX:80>
ServerName dev.abc.com
ServerAlias www.dev.abc.com
DocumentRoot /var/www/dev.abc.com/public/
</VirtualHost>
Try removing 'ServerName abc.com' from below the 'NameVirtualHost' part; it can mess your config
Have you checked the general error log? Maybe the reboot failed because of a misconfiguration?
I've been using this tutorial to set up an Apache virtual host on my Ubuntu pc. I've created a no-ip domain which I will be using as the hostname of my virtual host. I've followed every step of the tutorial but it doesn't work. Here's the virtual host file and it's named crm2plus.ddns.net.conf:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#crm2plus.ddns.net
ServerName crm2plus.ddns.net
ServerAlias crm2plus.ddns.net
DocumentRoot /var/www/crm2plus.ddns.net/public_html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I've also added the ip and domain name pair to my local hosts file and here's how it looks:
23.253.21.201 shhasan.ddns.net
127.0.1.1 Ubuntu-Dev
127.0.0.1 localhost
99.250.71.177 crm2plus.ddns.net
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
When I navigate to crm2plus.ddns.net through chrome I get the web page not available page. shhasan.ddns.net is working fine. When I type ssh-keygen -H -F crm2plus.ddns.net into the terminal nothing shows up but when I type ssh-keygen -H -F shhasan.ddns.net this is what shows up:
# Host shhasan.ddns.net found: line 14 type RSA
followed by the RSA key.
I've also looked at the Apache error and access logs. The error logs have a lot of repetition of such line of code:
[Fri Nov 14 17:44:50.304782 2014] [mpm_prefork:notice] [pid 21927] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.5 configured -- resuming normal operations
[Fri Nov 14 17:44:50.304801 2014] [core:notice] [pid 21927] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 14 17:44:54.979832 2014] [mpm_prefork:notice] [pid 21927] AH00169: caught SIGTERM, shutting down
I searched for caught SIGTERM, shutting down and I found that this was part of normal operation. I have no idea of where I'm going wrong. It had worked previously for shhasan.ddns.net but it doesn't work for crm2plus.ddns.net.
All help and suggestions are greatly appreciated.
Update:
developer#Ubuntu-Dev:/etc/apache2$ ls
apache2.conf apache2.conf.dpkg-dist conf-enabled httpd.conf magic mods-enabled ports.conf~ sites-enabled
apache2.conf~ conf-available envvars httpd.conf~ mods-available ports.conf sites-available
developer#Ubuntu-Dev:/etc/apache2/sites-available$ ls
000-default.conf 000-default.conf~ 000-default.conf.dpkg-dist crm2plus.ddns.net.conf crm2plus.ddns.net.conf~ default.save default-ssl.conf shhasan.ddns.net.conf
developer#Ubuntu-Dev:/etc/apache2/sites-enabled$ ls
crm2plus.ddns.net.conf shhasan.ddns.net.conf
apache2.conf shortened version:
Include /etc/phpmyadmin/apache.conf
ServerName localhost
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride All
# Order deny,allow
# Deny from all
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
You could try using the Apache2.4 syntax for access control in the Virtual Host definition file, as you are using Apache2.4, then if you have not activated mod_access_compat.so it should work or if you have you can deactivate it.
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
I must admit I prefer to add the access control for a Virtual Host within the VH definition itself. Then you know with just a look whats actually going on. So you might consider doing it this way.
<VirtualHost *:80>
ServerAdmin webmaster#crm2plus.ddns.net
ServerName crm2plus.ddns.net
ServerAlias www.crm2plus.ddns.net
DocumentRoot /var/www/crm2plus.ddns.net/public_html
<Directory /var/www/crm2plus.ddns.net/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Also you should be careful when messing with this parameter in the httpd.conf file
<Directory />
Options FollowSymLinks
AllowOverride All
# Order deny,allow
# Deny from all
</Directory>
This controls Apache's access to the root folder, and of course you would not want to allow Apache or a hacker on your Apache access to the universe would you.
So I suggest you set this back to
<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>
Using the Apache2.4 syntax again of course.
Update: A slightly edited version of the above VH definition worked for crm2plus.ddns.net
<VirtualHost *:80>
ServerName crm2plus.ddns.net
ServerAlias crm2plus.ddns.net
ServerRoot /var/www/crm2plus.ddns.net/
DocumentRoot /var/www/crm2plus.ddns.net/public_html
<Directory "/var/www/crm2plus.ddns.net/public_html">
Options +Indexes +FollowSymLinks
Order allow,deny
Allow from all
AllowOverride All
</Directory>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/crm2plus.ddns.net_error.log
CustomLog ${APACHE_LOG_DIR}/crm2plus.ddns.net_access.log combined
</VirtualHost>
Check your /etc/nsswitch.conf file. On my Ubuntu 14.04LTS I have to change line:
hosts: files mdns4_minimal [NOTFOUND=return] dns
to:
hosts: dns files mdns4_minimal [NOTFOUND=return]
In order to make Virtual Hosts work.
Am configuring a local linux development environment utilizing apache, i can access the url:
http://localhost:8080
but not the configured virtualhost entries which are also present in the /etc/hosts file e.g if i enter:
http://admin:8080
in my browser redirects me to www.admin.com, which is an external address.
/etc/hosts file has the following entries:
127.0.0.1 localhost admin jobboard
127.0.1.1 rob-VirtualBox
Apache config(virtual hosts reference the above entries admin and jobboard):
Listen 8080
Port 8080
ServerName 127.0.0.1:8080
DocumentRoot "/var/www/html/BigRedSkyASAP/virtualhosts"
<Directory "/var/www/html/BigRedSkyASAP/virtualhosts">
NameVirtualHost *:8080
<VirtualHost 127.0.0.1:8080>
ServerName admin
# set the document root
DocumentRoot "/var/www/html/BigRedSkyASAP/virtualhosts/Client-asap.bigredsky.com"
# set the directory settings
<Directory "/var/www/html/BigRedSkyASAP/virtualhosts/Client-asap.bigredsky.com">
Options All Includes Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost 127.0.0.1:8080>
ServerName jobboard
# set the document root
DocumentRoot "/var/www/html/BigRedSkyASAP/virtualhosts/JobBoard-asapdev.bigredsky.com"
# set the directory settings
<Directory "/var/www/html/BigRedSkyASAP/virtualhosts/JobBoard-asapdev.bigredsky.com">
Options All Includes Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Apache and Computer was restarted after changes to config files were saved.
Is their some other hosts configuration file which needs to be modified? Running linux mint OS.
Thanks in advance.
in the virtual host config try this for admin
ServerAlias admin
that should resolve the admin website to local server
furthermore check whether you are under any proxy...you should turn it off...
create one more vhost entry for admin
<VirtualHost 127.0.0.1:8080>
ServerName admin
I'm trying to get an SVN server up and running. CentOS 6.4, apache 2.2.15. More importantly, I need to have it running on https only. So I figure that I'll get ssl running first, as I've already tested it on port 80, and SVN works the way I want it to.
In /etc/httpd/ssl, I have ..
intermediate.crt wildcard.mycompany.com.crt wildcard.mycompany.com.key
We bought a wildcard certificate from GeoTrust, and I downloaded the intermediate.crt from their website. In /etc/httpd/httpd.conf, I have..
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin my.email#mycompany.com
ServerName hostname.mycompany.com
ErrorLog logs/error_log
CustomLog logs/access_log common
Redirect permanent / https://hostname.mycompany.com
</VirtualHost>
<VirtualHost hostname.mycompany.com:443>
SSLEngine On
SSLCertificateFile /etc/httpd/ssl/wildcard.mycompany.com.crt
SSLCertificateKeyFile /etc/httpd/ssl/wildcard.mycompany.com.key
SSLCertificateChainFile /etc/httpd/ssl/intermediate.crt
ServerName hostname.mycompany.com
ServerAdmin my.email#mycompany.com
ErrorLog logs/subversion-error_log
CustomLog logs/subversion-access_log common
</VirtualHost>
I can connect to the server, but my browser tells me that the certificate is untrusted. So I'm guessing that there's an error in the permissions, or perhaps in the format of the file?
I can't see anything in the logs.
I set this up at home on my own server, but wasn't using a wildcard certificate.
Anyone care to advise as to what's gone wrong?
Thanks.
I set Centos 6.3 up on a Rackspace box, using a static IP address (not a FQDN). I will be setting up virtual hosts on this box, and it seems to be working fine, but when I restart the HTTPD server, I get an error message "could not reliably determine the server's fully qualified domain name, using xx.xxx.xx.xx for ServerName" (xx.xxx.xx.xx is the static IP address for the server).
My /etc/hosts has the following in it:
27.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
xx.xxx.xx.xx name-used-for-rackspace
name-used-for-racspace is a name (not a FQDN) I used when I created the server (you have to enter a name).
I assume that I may not have to change anything in /etc/hosts, but what do I put in httpd.conf? right now, I have the following in that file:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName localhost
<Directory /var/www/html>
allow from all
Options +Indexes
</Directory>
</VirtualHost>
I also tried setting ServerName to xx.xxx.xx.xx, but I got the same error message.
This error is because you are not using a FQDN. It should not affect the operation of the webserver.
To get rid of the message on startup you'd need to configure your hosts file with the correct domain and IP address. Your httpd.conf should also use the same name (where you have localhost specified).
As long as your server is starting and you don't plan on assigning a domain to your webserver, this error can be ignored.
Example virtual host with FQDN:
<VirtualHost *:80>
ServerName www.domain.net
ServerAlias domain.net *.domain.net
ServerAdmin administrator#domain.net
DocumentRoot "/home/domain/htdocs"
<Directory "/home/domain/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
CustomLog "/home/domain/logs/access-www.log" common
ErrorLog "/home/domain/logs/error-www.log"
<IfModule mpm_peruser_module>
ServerEnvironment apache apache
</IfModule>
</VirtualHost>
Example hosts file:
127.0.0.1 localhost localhost.localdomain gentoo1
x.x.x.x gentoo1.domain.net
You need to configure the network connection with your static IP, see reference below. Otherwise, your web server is working, but it's not accessible externally.
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Configuring_IPv4_Settings.html
Then put the static IP in the httpd.conf after server name.