时间:2023-06-28 13:09:01 | 来源:网站运营
时间:2023-06-28 13:09:01 来源:网站运营
Apache的简介与配置(下):一、Apache配置文件简介# 在/usr/local/apache2/htdocs(网页文件目录)下创建.htaccess文件$ vim .htaccess authname "welcome to apahce"¥ authtype basic authuserfile /usr/local/apache2/htdocs/a.psd #指明账户文件所在目录 require valid-user# 创建用户$ useradd lisi$ useradd likui#将系统用户转化成apache用户并生成a.psd文件$ /usr/local/apache2/bin/htpasswd -c /usr/local/apache2/htdocs/a.psd lisi$ /usr/local/apache2/bin/htpasswd -m /usr/local/apache2/htdocs/a.psd likui# 已经有一个以上的apache用户需要用选项:-m# 修改主配置文件$ vi /usr/local/apache2/etc/htpd.conf AllowOverride All# 开启apache$ /usr/local/apache2/bin/apachectl# 测试
# 修改配置文件$ vim /usr/local/apache2/conf/httpd.conf <requireall> require all granted require ip xx.xx.xx.xx </requireall># 允许该IP访问 <requireall> require all granted require not ip xx.xx.xx.xx </requireall># 重启$ /usr/local/apache2/bin/apachectl stop$ /usr/local/apache2/bin/apachectl start# 测试
# 修改主配置文件,取消vhost模块的注释$ vim /usr/local/apache2/conf/httpd.conf Include etc//extra/httpd-vhosts.conf# 修改虚拟主机模块配置文件$ vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 如下图# 创建网页文件保存路径$ mkdir /data/www1$ mkdir /data/www2# 写入网页文件$ echo "www1.linux.com" >> /data/www1/index.html$ echo "www2.linux.com" >> /data/www2/index.html# 修改hosts文件,便于解析域名$ vim /etc/hosts# 测试
#修改apache的主配置文件---取消相关模块的注释$ vim /usr/local/apache2/conf/http.conf LoadModule userdir_module modules/mod_userdir.so Include etc//extra/httpd-userdir.conf #查看apache主页文件所在目录$ vim /usr/local/apache2/conf/extra/httpd-userdir.conf#创建用户并修改密码$ useradd lisi$ passwd lisi# 创建个人主页文件$ cd /home/lisi$ mkdir public_html$ echo "this is lisi's house" > index.html# 授权$ chmod a+x /home/lisi#测试
# 修改apache配置文件,取消模块相关配置$ vim /usr/local/apache2/conf/httpd.conf LoadModule vhost_alias_module modules/mod_vhost_alias.so LoadModule rewrite_module modules/mod_rewrite.so Include conf/extra/httpd-vhosts.conf# 修改vhost配置文件$ vim /usr/local/apache2/conf/extra/httpd.conf# 如图
# 创建网页文件所在目录及网页文件$ mkdir /data/www1 -p$ mkdir /data/www2 -p$ echo "www1" >> /data/www1/index.html$ echo "www2" >> /data/www2/index.html# 用.htaccess文件实现地址跳转$ vim .htaccess rewriteengine on rewritecond %{HTTP_HOST} www1.linux.com rewriterule .* http://www2.linux.com# 重启apache,并修改windows的hosts文件$ /usr/local/apache2/bin/apachectl start#测试
关键词:配置