Home  >  Article  >  Operation and Maintenance  >  How to bind domain name with apache

How to bind domain name with apache

步履不停
步履不停Original
2019-06-28 15:38:308876browse

How to bind domain name with apache

Apache binding domain name

If you want the domain name of your online project to resolve to your local IP ,how should I do it? Do I need to change the configuration files one by one?

Example: The domain name is aaa.com

The default port is 80.

I tried to change it to port 8080, but an error occurred

1. Local hosts

What are local hosts? We know that to access a domain name, get the IP address of the server pointed to by the domain name through the DNS server, and then establish a connection with the server through the IP address to complete the rest. So how can we simulate a domain name when we don't have a domain name during the development process? The answer is the hosts file
address: C:\Windows\System32\Drivers\etc\hosts Open it with Notepad and add a line at the end:

127.0.0.1 localhost  aaa.com

2.apache virtual host Configuration

Assuming that apache is installed in x:\apache, then open x:\apache\conf\httpd.conf first and look for "Include conf/extra/httpd-vhosts.conf". If there is a '#' in front of it, Delete it. If there is no such statement, add it manually

Then go to find the directory where you installed Apache. For example: D:\xampp\apache\conf\extra Find or create a new directory httpd-vhosts.conf file (if the domain name you want to resolve is the http protocol, modify it here, if it is the HTTPS protocol, modify the httpd-ssl.conf file), after opening the file, add

at the end :

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "D:/EmpireServer/web"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost-error_log"
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "D:/EmpireServer/web" (此处意思为,你对应解析的域名的代码位置)
    ServerName aaa.com (此处地址与你在hosts文件中写的一样)
    ServerAlias *.aaa.com ( 识别解析生成的域名)
    ErrorLog "logs/localhost-error_log"
</VirtualHost>

When the virtual host function is turned on, all requests will enter 68d48e2a995e54b6ad4a8d83ae91217c, and the first 68d48e2a995e54b6ad4a8d83ae91217c will be used as the default processing configuration, that is, www .aaa.com will enter the second 68d48e2a995e54b6ad4a8d83ae91217c,

and other unmatched ones will enter the first 68d48e2a995e54b6ad4a8d83ae91217c configuration, such as the localhost series.

3. Open port 80

The port must be open.

Also here, because the server resolves the domain name, I did not test whether apache's resolution is effective.

For more technical articles related to Apache, please visit the Apache Tutorial column to learn!

The above is the detailed content of How to bind domain name with apache. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn