How to configure multiple different sites and domain names in apache2.4 server

user:visitors Date:2021-12-19 16:00:341882

In the windows system environment, we generally use apache as a web server to run common websites. If only one website is placed in the server, it is too wasteful of resources for a server with a larger storage space, so how to store it in a server How about running multiple website projects?

To configure a website with apache, we first need to modify the configuration file in the installed apche.

Open the httpd.conf file in the conf folder.

Remove the # sign in front of Include conf/extra/httpd-vhosts.conf.

Then modify the httpd-vhosts.conf file in the conf/extra/ folder

Delete the default configuration and add the following code:

<VirtualHost *:80>

DocumentRoot "C:/wz1"

ServerName first-level domain name

ServerAlias second-level domain name with www

# ErrorLog "logs/wz1-error.log"

# CustomLog "logs/wz1-access.log" common

<Directory "C:/wz1">

Require all granted

</Directory>

</VirtualHost>

<VirtualHost *:80>

DocumentRoot "C:/wz2"

ServerName first-level domain name

ServerAlias second-level domain name with www

# ErrorLog "logs/wz2-error.log"

# CustomLog "logs/wz2-access.log" common

<Directory "C:/wz2">

Require all granted

</Directory>

</VirtualHost>

Where VirtualHost *:80 matches port 80, DocumentRoot sets the root directory of each site, ServerName sets the top-level domain name, and ServerAlias sets the website alias by adding www in front of the domain name, so that you can bind to a site with www and not at the same time. Two domain names.

Set the root directory permissions and access rules in the Directory code snippet. Here we set to allow all users to access the directory. If it is not set, the website may not be opened or a 403 error may occur. Of course, we can also add some other settings above the code:

like:

Options FollowSymLinks #Options setting

AllowOverride All #Allow .htaccess rules to override Options settings

In the apache server, to configure multiple sites, you can follow the example wz1 and wz2 site configuration methods, copy the VirtualHost code segment into multiple copies, and then modify the bound site configuration.

The above is only to set up the site configuration of 80 port http. If we need to set up multiple https, how should we configure it?

In apache, there are various configuration example files, we only need to add the following in the apache configuration file httpd.conf code:

Module:

LoadModule ssl_module modules/mod_ssl.so

And site configuration file:

Include conf/extra/httpd-ahssl.conf

Remove the # in front

Then modify the httpd-ahssl.conf file in the conf/extra folder

<VirtualHost _default_:443></virtualhost> delete

Add code:

<VirtualHost *:443>

SSLEngine on

ServerName first-level domain name: 443

ServerAlias second-level domain name with www: 443

SSLCertificateFile "C:/ssl/public.crt"

SSLCertificateKeyFile "C:/ssl/key.key"

SSLCertificateChainFile "C:/ssl/chain.crt"

DocumentRoot "C:/wz1"

<Directory "C:/wz1">

Options Indexes Includes FollowSymLinks

Require all granted

</Directory>

</virtualhost>

Among them, SSLCertificateFile sets the public key, SSLCertificateKeyFile sets the private key, and SSLCertificateChainFile sets the general key. Another configuration is:

SSLCertificateFile "C:/ssl/public.crt"

SSLCertificateKeyFile "C:/ssl/key.key"

The setting of SSLCertificateChainFile is missing because the content of SSLCertificateFile and SSLCertificateChainFile needs to be combined.

Same as the setting method of multiple sites in http, copy multiple copies of the code in <VirtualHost *:443> to </virtualhost>, and then modify ServerName, the domain name bound by ServerAlias, SSLCertificateFile, SSLCertificateKeyFile, SSLCertificateChainFile ssl certificate, DocumentRoot and Directory website directory address, and then save and restart apache to complete the configuration of multiple sites and domain names.

The above is in the win system, apache2.4 configures multiple different site projects and bound domain names, and sets the http and https protocols for multiple projects separately.

Popular articles
latest article