Apache部署静态网站

  1. Apache安装(Linux安装Apache)
  2. 网站模板(https://sc.chinaz.com/moban)
  3. Apache配置
    https://httpd.apache.org/docs/2.4/vhosts/examples.html

    1.编辑:/opt/apache/httpd-2.4.54/conf/httpd.conf
    # Ensure that Apache listens on port 80
    Listen 80
    <VirtualHost *:80>
        DocumentRoot "/opt/apache/website/myweb001"
        ServerName www.example.com
    
        # Other directives here
        <Directory "/opt/apache/website/myweb001">
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
        </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot "/opt/apache/website/myweb002"
        ServerName www.example.org
    
        # Other directives here
        <Directory "/opt/apache/website/myweb002">
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
        </Directory>
    </VirtualHost>
    注意:/opt/apache/website/myweb001和/opt/apache/website/myweb002为静态网站在虚拟机中的路径
     
    2.重启Apache:httpd -k restart
     
    3.防火墙打开端口权限:firewall-cmd --zone=public --add-port=80/tcp --permanent && firewall-cmd --reload
    
    4.编辑:C:\Windows\System32\drivers\etc\hosts
    192.168.1.97 www.example.org
    192.168.1.97 www.example.com
    
    解释说明:
    C:\Windows\System32\drivers\etc\hosts为主机hosts文件,可以将域名www.example.org和www.example.com
    映射为虚拟机ip,主机浏览器输入www.example.org和www.example.com等价于输入192.168.1.97,http的默认端口
    为80,主机浏览器输入192.168.1.97等价于输入192.168.1.97:80,这样就可以定位到虚拟机Apache服务,然后根据主
    机浏览器输入的域名找到对应的ServerName为所输入域名的VirtualHost,这样就可以访问到对应的静态网站了,实际
    应用中静态网站部署在云服务器,只需要将购买的域名解析为云服务器的公网ip即可


  4. 网站访问
    www.example.orgwww.example.com

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

童心同萌

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值