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