2

How can I modify httpd.conf to add one more site in Apache 2.4.6? Here is my httpd.conf:

ServerRoot "/etc/httpd"
Include conf.modules.d/*.conf
Listen 80
User apache
Group apache
ServerAdmin root@localhost
ServerName xx.xx.xx.xx:80
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 150
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
<Directory />
    AllowOverride none
    Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
<IfModule dir_module>
     DirectoryIndex index.html
</IfModule>
<Files ".ht*">
    Require all denied
</Files>
ErrorLog logs/error_log
LogLevel crit
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined env=!dontlog
    CustomLog "logs/my_log" combined env=!dontlog
    #CustomLog "|sbin/rotatelogs -f logs/my_log 60" combined env=!dontlog
    SetEnvIf Remote_Addr "::1" dontlog
</IfModule>
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>
<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    HostnameLookups Off
    ProxyPreserveHost On
    DocumentRoot /var/www/html
    RLimitCPU 120|max
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
<VirtualHost *:80>
    HostnameLookups Off
    ProxyPreserveHost On
    DocumentRoot /var/www/html
    RLimitCPU 120|max
    ServerName domain1.com
    <directory "/var/www/html">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </directory>
</VirtualHost>
ExpiresActive On
<FilesMatch "\.(jpg|jpeg)$">
</FilesMatch>
<FilesMatch "\.(css|png|js|gif)$">
 ExpiresDefault "access plus 1 month"
</FilesMatch>

<ifmodule deflate_module>
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
</ifmodule>

My problem is I have already one site in '/var/www/html' with domain1.com. If I add one more site domain2.com, create a new folder like /var/www/new or /var/www/html/new, how can I modify the <VirtualHost *:80> part? Because I have defined DocumentRoot /var/www/html. Thanks.

1

My problem is I have already one site in '/var/www/html' with domain1.com. If I add one more site domain2.com create a new folde like /var/www/new or /var/www/html/new, how to modify <VirtualHost *:80> part? because I have deified DocumentRoot /var/www/html.

I'm not really sure what the "problem" is? You copy the entire <VirtualHost *:80> container for each site you want to configure, changing the ServerName, DocumentRoot and <Directory> containers appropriately. The <VirtualHost *:80> opening "tag" remains unchanged for name-based virtual hosts.

Whichever ServerName matches the Host in the HTTP request header controls which <VirtualHost> is used. This <VirtualHost> overrides any default settings (DocumentRoot etc.) you might have in the main config file.

a new folde like /var/www/new or /var/www/html/new

If these are entirely separate sites it might be preferable to have them in separate directory trees because of how Apache config / .htaccess inherit along the filesystem path. (Although this can also be used to your advantage if you are managing a cluster of sites. eg. blocking bad bots in one place, rather than for each site separately.)

If you have more than a couple virtual hosts on your server it is easier (more modular) to have your virtual hosts in a separate file and include them in the main Apache config, for example:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.