centos7中Apache的使用

1、Apache基本操作

安装:yum install httpd
启动:service httpd start
停止:service httpd stop

        安装完httpd,启动http服务,查看服务是否已启动,service httpd status

        如果centos中开启了防火墙,则要先将http去服务添加进防火墙配置,否则无法访问。

firewall-cmd --add-service=http

        访问Apache web服务器http://xxx.xxx.xxx.xxx:80,成功即可进入服务器

2、Apache虚拟主机配置

<VirtualHost *:80>
    ServerName www.imooc.test
    DocumentRoot /data/www
</VirtualHost>

        配置完毕之后,重启apache服务器

service httpd restart

        配置/etc/hosts,将域名解析到本地IP

192.168.43.225 www.imooc.test

        重新编辑VirtualHost配置

<VirtualHost *:80>
    ServerName www.imooc.test
    DocumentRoot /data/www
    <Directory "/data/www">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

        重启apache服务器,访问测试 curl -I www.imooc.test,返回状态码200

        提示:如果访问仍是403,可以尝试以下命令:

setenforce 0

3、伪静态

        可以参考: 什么是伪静态?伪静态有何作用?

        导入rewrite模块

LoadModule rewrite_module modules/mod_rewrite.so

        添加伪静态规则

<VirtualHost *:80>
    ServerName www.imooc.test
    DocumentRoot /data/www
    <Directory "/data/www">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteRule ^(.*).htmp$ index.html
        </IfModule>
    </Directory>
</VirtualHost>

        重启apache,测试一下 curl www.imooc.test/1.htmp

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值