Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
So I've built this server and it works fine, I really like the iRedMail BUT......
It changed the default apache2 config files and I can't for the life of me figure out how to get name based virtual websites working.
httpd.conf
Code:
NameVirtualHost *:80
### Global Environment ######################################################
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests.
# run under this user/group id
Include /etc/apache2/uid.conf
# - how many server processes to start (server pool regulation)
# - usage of KeepAlive
Include /etc/apache2/server-tuning.conf
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
ErrorLog /var/log/apache2/error_log
# generated from APACHE_MODULES in /etc/sysconfig/apache2
Include /etc/apache2/sysconfig.d/loadmodule.conf
# IP addresses / ports to listen on
Include /etc/apache2/listen.conf
# predefined logging formats
Include /etc/apache2/mod_log_config.conf
# generated from global settings in /etc/sysconfig/apache2
Include /etc/apache2/sysconfig.d/global.conf
# optional mod_status, mod_info
Include /etc/apache2/mod_status.conf
Include /etc/apache2/mod_info.conf
# optional cookie-based user tracking
# read the documentation before using it!!
Include /etc/apache2/mod_usertrack.conf
# configuration of server-generated directory listings
Include /etc/apache2/mod_autoindex-defaults.conf
# associate MIME types with filename extensions
TypesConfig /etc/apache2/mime.types
DefaultType text/plain
Include /etc/apache2/mod_mime-defaults.conf
# set up (customizable) error responses
Include /etc/apache2/errors.conf
# global (server-wide) SSL configuration, that is not specific to
# any virtual host
Include /etc/apache2/ssl-global.conf
# forbid access to the entire filesystem by default
<Directory />
Options None
AllowOverride None
Order deny,allow
Deny from all
</Directory>
# use .htaccess files for overriding,
AccessFileName .htaccess
# and never show them
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
# List of resources to look for when the client requests a directory
DirectoryIndex index.html index.html.var
### 'Main' server configuration #############################################
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition. These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#
Include /etc/apache2/default-server.conf
# Another way to include your own files
#
# The file below is generated from /etc/sysconfig/apache2,
# include arbitrary files as named in APACHE_CONF_INCLUDE_FILES and
# APACHE_CONF_INCLUDE_DIRS
Include /etc/apache2/sysconfig.d/include.conf
### Virtual server configuration ############################################
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
Include /etc/apache2/vhosts.d/*.conf
# Note: instead of adding your own configuration here, consider
# adding it in your own file (/etc/apache2/httpd.conf.local)
# putting its name into APACHE_CONF_INCLUDE_FILES in
# /etc/sysconfig/apache2 -- this will make system updates
# easier :)
default-server.conf
Code:
#
# Global configuration that will be applicable for all virtual hosts, unless
# deleted here, or overriden elswhere.
#
DocumentRoot "/srv/www/htdocs"
#
# Configure the DocumentRoot
#
<Directory "/srv/www/htdocs">
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs-2.2/mod/core.html#options
# for more information.
Options None
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
AllowOverride None
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
</Directory>
# Aliases: aliases can be added as needed (with no limit). The format is
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL. So "/icons" isn't aliased in this
# example, only "/icons/". If the fakename is slash-terminated, then the
# realname must also be slash terminated, and if the fakename omits the
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings. If you
# do not use FancyIndexing, you may comment this out.
#
Alias /icons/ "/usr/share/apache2/icons/"
<Directory "/usr/share/apache2/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
# "/srv/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/srv/www/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
</Directory>
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# To disable it, simply remove userdir from the list of modules in APACHE_MODULES
# in /etc/sysconfig/apache2.
#
<IfModule mod_userdir.c>
# Note that the name of the user directory ("public_html") cannot simply be
# changed here, since it is a compile time setting. The apache package
# would have to be rebuilt. You could work around by deleting
# /usr/sbin/suexec, but then all scripts from the directories would be
# executed with the UID of the webserver.
UserDir public_html
# The actual configuration of the directory is in
# /etc/apache2/mod_userdir.conf.
Include /etc/apache2/mod_userdir.conf
</IfModule>
# Include all *.conf files from /etc/apache2/conf.d/.
#
# This is mostly meant as a place for other RPM packages to drop in their
# configuration snippet.
#
# You can comment this out here if you want those bits include only in a
# certain virtual host, but not here.
#
Include /etc/apache2/conf.d/*.conf
# The manual... if it is installed ('?' means it won't complain)
Include /etc/apache2/conf.d/apache2-manual?conf
ServerName linux01.mydomain.com
ServerAdmin admin@mydomain.com
default-vhost.conf
Code:
<VirtualHost _default_:8080>
ServerName dummy-host.example.com
ServerAdmin webmaster@dummy-host.example.com
ServerAlias example.com www.example.com
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot "/srv/www/htdocs"
# if not specified, the global error log is used
ErrorLog /var/log/apache2/dummy-host.example.com-error_log
CustomLog /var/log/apache2/dummy-host.example.com-access_log combined
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
#UseCanonicalName Off changed by jeff 9/18/13
UseCanonicalName Off
# configures the footer on server-generated documents
ServerSignature On
# Optionally, include *.conf files from /etc/apache2/conf.d/
#
# For example, to allow execution of PHP scripts:
#
# Include /etc/apache2/conf.d/mod_php4.conf
#
# or, to include all configuration snippets added by packages:
# Include /etc/apache2/conf.d/*.conf
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
# "/srv/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have one, and where ScriptAlias points to.
#
<Directory "/srv/www/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
</Directory>
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# To disable it, simply remove userdir from the list of modules in APACHE_MODULES
# in /etc/sysconfig/apache2.
#
<IfModule mod_userdir.c>
# Note that the name of the user directory ("public_html") cannot simply be
# changed here, since it is a compile time setting. The apache package
# would have to be rebuilt. You could work around by deleting
# /usr/sbin/suexec, but then all scripts from the directories would be
# executed with the UID of the webserver.
UserDir public_html
# The actual configuration of the directory is in
# /etc/apache2/mod_userdir.conf.
Include /etc/apache2/mod_userdir.conf
# You can, however, change the ~ if you find it awkward, by mapping e.g.
# http://www.example.com/users/karl-heinz/ --> /home/karl-heinz/public_html/
#AliasMatch ^/users/([a-zA-Z0-9-_.]*)/?(.*) /home/$1/public_html/$2
</IfModule>
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/srv/www/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs-2.2/mod/core.html#options
# for more information.
#
Options +Indexes +MultiViews +FollowSymLinks
IndexOptions FancyIndexing
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
#
# some Rewrite stuff for sharedssl
#
#RewriteEngine on
##RewriteLog "/var/log/apache2/dummy-host.example.com-rewrite_log"
##RewriteLogLevel 3
#RewriteCond %{HTTP_HOST} ^sharedssl\.* [OR]
#RewriteRule ^/$ https://sharedssl.example.com/$1 [L,R]
</VirtualHost>
/etc/apache2/vhosts.d/main.conf
Code:
<VirtualHost *:80>
UseCanonicalName On
ServerAdmin admin@mydomain.com
DocumentRoot "/srv/www/htdocs/mydomain.com"
ServerName www.mydomain.com
ServerAlias mydomain.com
ErrorLog "/var/log/apache2/mydomain.com-error_log"
CustomLog "/var/log/apache2/mydomain.com-access_log" common
</VirtualHost>
ip-based_vhosts.conf (added by iRedMail I believe)
Code:
<VirtualHost *:443>
ServerAdmin postmaster@mydomain.com
DocumentRoot /srv/www/htdocs
# Enable SSL.
SSLEngine On
SSLCertificateFile /etc/apache2/ssl.crt/mydomain.com.crt
#SSLCertificateFile /etc/ssl/certs/iRedMail_CA.pem
SSLCertificateKeyFile /etc/apache2/ssl.key/mydomain.com
#SSLCertificateKeyFile /etc/ssl/private/iRedMail.key
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "/srv/www/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin "/srv/www/cgi-bin"
<Directory "/srv/www/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
</Directory>
<IfModule mod_userdir.c>
UserDir public_html
Include /etc/apache2/mod_userdir.conf
</IfModule>
Alias /iredadmin/static "/srv/www/iredadmin/static/"
WSGIScriptAlias /iredadmin "/srv/www/iredadmin/iredadmin.py/"
Alias /mail "/srv/www/roundcubemail/"
Alias /phpmyadmin "/srv/www/htdocs/phpMyAdmin/"
</VirtualHost>
<VirtualHost *:80>
ServerAdmin postmaster@mydomain.com
DocumentRoot /srv/www/htdocs/
ErrorLog /var/log/apache2/
CustomLog /var/log/apache2/
HostnameLookups Off
UseCanonicalName Off
ServerSignature Off
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "/srv/www/htdocs/">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin "/srv/www/cgi-bin"
<Directory "/srv/www/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
</Directory>
<IfModule mod_userdir.c>
UserDir public_html
Include /etc/apache2/mod_userdir.conf
</IfModule>
</VirtualHost>
when I point to the localhost I get a bad request error:
Quote:
Bad request!
Your browser (or proxy) sent a request that
this server could not understand.
If you think this is a server error, please contact
the webmaster.
error 400
linux01.mydomain.com
Wed Sep 18 14:38:00 2013
Apache
what am I missing here? this is driving me nuts...
Bad request!
Your browser (or proxy) sent a request that
this server could not understand.
If you think this is a server error, please contact
the webmaster.
Most likely you're trying to connect to the server ssl port (443) using http protocol. Try https://servername and see what you get
To check your vhosts, you can run:
Also look into /var/log/apache2/mydomain.com-error_log if it is not the content installed in your vhost which is returning an error.
I would also try to separate the different host physically.
If I'm not mistaken, you use /srw/www/htdocs twice and the mydomain vhost is also inside that structure in /srv/www/htdocs/mydomain.com and Apache may apply options from other vhosts to your mydomain.com vhost
So maybe a layout like
/srv/www/htdocs for the main host
/srv/www/httpsdocs for the ssl host and
/srv/www/vhosts/mydomain.com for the first vhost
would be easier to debug
Also look into /var/log/apache2/mydomain.com-error_log if it is not the content installed in your vhost which is returning an error.
I would also try to separate the different host physically.
If I'm not mistaken, you use /srw/www/htdocs twice and the mydomain vhost is also inside that structure in /srv/www/htdocs/mydomain.com and Apache may apply options from other vhosts to your mydomain.com vhost
So maybe a layout like
/srv/www/htdocs for the main host
/srv/www/httpsdocs for the ssl host and
/srv/www/vhosts/mydomain.com for the first vhost
would be easier to debug
That's definitely a cleaner structure. I'll do that.
There is nothing in the mydomain.com-error_log at all. Seems everything gets redirected to ssl (443) and automatically appended with "/mail"
this is part of the iRedMail modifications and while that's great if all you're running is the iRedMail server, it's problematic if you want to have vhosts and other websites on the server.
1) why is http (non ssl) not allowed?
2) how do I get it to server up /srv/www/mydomain.com/index.html as opposed to /srv/www/htdocs/index.html
1. There should be some RewriteRule that turns http to https
2. Change the DocumentRoot of the vhost in question to /srv/www/mydomain.com. You may need to use
Code:
<Directory /srv/www/mydomain.com>
Allow from All
</Directory>
as that directory is outside the server default DocumentRoot
1. There should be some RewriteRule that turns http to https
yes but where?
Quote:
2. Change the DocumentRoot of the vhost in question to /srv/www/mydomain.com. You may need to use
Code:
<Directory /srv/www/mydomain.com>
Allow from All
</Directory>
as that directory is outside the server default DocumentRoot
where would I put the <Directory ....> statement? in the mydomain.conf vhost file or back in the man httpd.conf?
I create another vhost:
Code:
<VirtualHost *:80>
UseCanonicalName On
ServerAdmin me@mydomain.com
DocumentRoot "/srv/www/testdomain.com"
ServerName www.testdomain.com
ServerAlias testdomain.com
ErrorLog "/var/log/apache2/testdomain.com-error_log"
CustomLog "/var/log/apache2/testdomain.com-access_log" common
</VirtualHost>
as expected it only works with https and it only serves up the /srv/www/htdocs/index.html
it's as if it's ignoring name based vhosts and only using ip-based.
I'm thinking my devil is in here...
/etc/apache2/default-vhost.conf
Code:
<VirtualHost _default_:8080>
ServerName dummy-host.example.com
ServerAdmin webmaster@dummy-host.example.com
ServerAlias example.com www.example.com
.
DocumentRoot "/srv/www/htdocs"
ErrorLog /var/log/apache2/dummy-host.example.com-error_log
CustomLog /var/log/apache2/dummy-host.example.com-access_log combined
HostnameLookups Off
UseCanonicalName Off
ServerSignature On
ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
<Directory "/srv/www/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
</Directory>
<IfModule mod_userdir.c>
UserDir public_html
Include /etc/apache2/mod_userdir.conf
</IfModule>
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/srv/www/htdocs">
Options +Indexes +MultiViews +FollowSymLinks
IndexOptions FancyIndexing
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Last edited by Ashcor; 09-19-2013 at 01:22 PM.
Reason: additional thoughts...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.