Domain name binding and virtual host configuration skills for building a web server on CentOS
Introduction:
When building a web server, domain name binding and virtual host configuration are a very important step. This article will introduce how to configure domain name binding and virtual host on CentOS, and provide corresponding code examples.
1. Domain name binding
sudo vi /etc/hosts
Add the following line at the end of the file, where "www.example.com" is the customized domain name, "192.168.0.100" is the IP address of the server:
192.168.0.100 www.example.com
Save and close the file.
sudo vi /etc/httpd/conf/httpd.conf
Find and modify the following line, replace "www.example.com "Change to the domain name you want to bind:
ServerName www.example.com:80
Save and close the file.
Restart the Apache service to make the configuration take effect:
sudo service httpd restart
2. Virtual host configuration
sudo mkdir /var/www/virtual_host
sudo vi /etc/httpd/conf.d/httpd-vhosts.conf
At the end of the file, add the following content and replace "example.com" is your domain name, "/var/www/virtual_host/example.com" is the directory path you just created:
ServerName example.com DocumentRoot /var/www/virtual_host/example.com <Directory /var/www/virtual_host/example.com> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
Save and close the file.
sudo chown -R apache:apache /var/ www/virtual_host/example.com
sudo chmod -R 755 /var/www/virtual_host/example.com
sudo service httpd restart
At this point, the configuration of the virtual host is completed.
Code example:
sudo vi /var/www/virtual_host/example.com/index.html
Paste the following into the file:
< html>
<title>Welcome to example.com!</title>
<h1>Welcome to example.com!</h1> <p>This is the default web page for the domain example.com.</p>
Save and close the file.
Summary:
This article introduces the techniques for domain name binding and virtual host configuration on CentOS. By modifying the hosts file, configuring DNS resolution and related configuration of Apache, it is possible to point the domain name to Correct directory purpose. At the same time, code examples for creating the virtual host directory and homepage are also provided to facilitate readers to practice and test.
I hope this article will help you with domain name binding and virtual host configuration when building a web server on CentOS.
The above is the detailed content of Domain name binding and virtual host configuration skills for building a web server on CentOS. For more information, please follow other related articles on the PHP Chinese website!