Linux 虚拟主机的配置

前提是已经安装过 apache

第一步:编辑 vim /etc/httpd/conf/httpd.conf

在 httpd.conf 任意位置,最好在最下方中添加代码


    NameVirtualHost *:80
    <VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot /var/www/html
        ServerName www.fatboss.com
        <Directory "/var/www/html">
            Options Indexes FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
        ErrorLog logs/test.com-error_log
        CustomLog logs/test.com-access_log common
    </VirtualHost>

效果如下图:

第二步:vim /etc/hosts

第三步:systemctl restart httpd.service

浏览器上访问:localhost

第四步

Windows 下 访问 linux 的虚拟域名

修改物理主机hosts文件(C:\Windows\System32\drivers\etc),因为这里是因为物理机去访问Apache服务器

把标红文件拖拽到桌面然后编辑(etc下文件不允许改动)

将 linux 服务器的 ip  与 虚拟域名 按如图方式填写

然后将 hosts 文件放回原处 (C:\Windows\System32\drivers\etc)即可

Windows下访问 域名

猜你喜欢

转载自blog.csdn.net/weixin_43033426/article/details/88749119