Apache configuration virtual host vhost (applicable and changed the Apache default listening port situation)


1. Edit httpd.conf and introduce the vhosts configuration file

Find vhosts.conf, delete its previous #number
vhosts.conf
Note: You can also create a virtual host configuration file yourself, using Include+配置文件路径the introduction to

Two, edit the vhosts configuration file

Open APACHE_HOME/conf/extra/httpd-vhosts.confor 你新创建的文件, add the following

<VirtualHost *:LISTEN_PORT>
    ServerAdmin [email protected]
    DocumentRoot "指定你的路径"
    ServerName example.net
    ServerAlias example.net
    ErrorLog "logs/vhosts.log"
    CustomLog "logs/vhosts.log" common
    # 如果 index 是 php 文件,那就必须要配置 index.php,或者你想展示的首页文件名
    # DirectoryIndex index.php
    <Directory "上面指定你的路径">
    	# -Indexes 是在没有 index 文件时不展示目录结构,可以看自己需求决定是否打开
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

Note:
① If there had been changes to httpd.confthe port after the LISTEN, modify the configuration text LISTEN_PORTyou specified port
Change the icon of the listening port
② Please keep only what you need and effective configuration of vhosts in the configuration file, remove excess

3. Edit the hosts file and add domain name resolution

Open C:\Windows\System32\drivers\etc\hostsfile is added to the inside, which domainneeds vhosts.confthe configuration file ServerNameor ServerAlias, the matching any one or all of which may

127.0.0.1 	example.net
::1			example.net

It is not recommended to use a domain name like css.dev , the actual test Chrome browser will not be able to request, I don’t know what caused it,

Fourth, restart Apache

  1. Use ApacheMonitor to restart Apache

Open the APACHE_HOME/binnext ApacheMonitor.exe
ApacheMonitor path
restart from the task bar, if not start, you can directly Start (after a successful start will turn green Apche2.4 ago)
mission Board
from the main interface to restart the ApacheMonitor (choose any of it)
panel

  1. Restart Apache from the service

Ctrl+ Alt+ ESCStart Task Manager, open the 服务tab, find Apache2.4, right-click to select Start (or restart)
service

Five, verify that the configuration is successful

Use any browser to open your configured domain name.
Note: If you modify the port of LISTEN in httpd.conf, please add : + your designated port after the domain name for access, such as
Inspection demonstration

Congratulations, you have solved this problem, continue to overcome the next difficulty!

Still have minor problems?

  1. Apache2.4Version Do not <Directory>use the label Order allow,deny, or allow from allother statements, can cause Apache failed to start because the new version does not support these two statements!
  2. You can leave a message below and I will try to solve it for you!

Guess you like

Origin blog.csdn.net/JikeStardy/article/details/107372870