欢迎光临散文网 会员登陆 & 注册

Centos7.6 http服务搭建全攻略

2021-08-13 17:52 作者:墨大仙仙仙  | 我要投稿

1、安装apache服务

yum  clean all

yum install -y httpd

2、启动服务并验证

systemctl  start httpd

浏览器127.0.0.1

3、创建网站根目录和首页文件

mkdir -p /data/www

chmod -R o+rx /data

echo "welcome to my website" >/data/www/index.html

cat  /data/www/index.html

4、修改apache主配置文件

cd /etc/httpd/conf

mv  httpd.conf httpd.conf.bak

grep -v "#" httpd.conf.bak>httpd.conf

vim httpd.conf

ServerName ns1.myj.edu.cn

DocumentRoot "/data/www"

<Directory "/data/www">

AllowOverride None

Require all granted

DirectoryIndex index.html

</Directory>

5、重启httpd服务,防火墙放行

systemctl restart httpd

firewall-cmd --permanent --add-service=http

firewall-cmd --reload

firewall-cmd --list-all

setenforce 0



拓展1:创建虚拟目录

1、创建虚拟目录和分配权限

mkdir - p /ito/www

chmod -R o+rx /ito

echo "this is in/ito/www">/ito/www/index.html

2、修改配置文件/etc/httpd/conf/httpd.conf

Alias /doc "/ito/www"

<Directory "/ito/www">

AllowOverride none

Require all granted

</Directory>

3、重启httpd服务

systemctl restart httpd


拓展2:创建用户个人主页

1、创建用户名和目录

useradd  myj

useradd myj2

chmod -R o+rx /home/myj

chmod -R o+rx /home/myj2

mkdir -p /home/myj/www

mkdir -p /home/myj2/www

echo "this is myjwww" > /home/myj/www/index.html

echo "this is myj2 www" > /home/myj/www/index.html

2、修改用户主页配置文件/etc/httpd/conf.d/userdir.conf

vim /etc/httpd/conf.d/userdir.conf

<IfModule mod_userdir.c>

#UserDir disabled

UserDir www

</IfModule>

<Directory "/home/*/public_html">

修改成

<Directory "/home/*/www">

3、重启httpd服务

systemctl restart httpd

4、验证http://192.168.128.100/~myj

             http://192.168.128.100/~myj2


拓展3:创建虚拟主机

1、修改网卡配置文件增加ip地址

cat /var/named/zone.myj.edu.cn

vim /etc/sysconfig/network-scripts/ifcfg-ens33

IPADDR0=192.168.128.100

PREFIX0=24

GATEWAY0=192.168.128.254

IPADDR1=192.168.128.120

PREFIX1=24

GATEWAY1=192.168.128.254

DNS1=192.168.128.100

systemctl restart network

2、创建虚拟主机的根目录和首页文件,分配权限

mkdir -p /data/www2

chmod -R o+rx /data/www2

echo "this is www.myj.edu.cn" > /data/www2/index.html

3、创建vhost.conf配置文件

vim /etc/httpd/conf.d/vhost.conf

<Virtualhost 192.168.128.100>

            DocumentRoot /data/www

    ServerName ns1.myj.edu.cn

            <Directory />

                AllowOverride none

                Require all granted

            </Directory>

</Virtualhost>

<Virtualhost 192.168.128.120>

            DocumentRoot /data/www2

            ServerName www.myj.edu.cn

            <Directory />

                AllowOverride none

                Require all granted

            </Directory>

</Virtualhost>

4、重启httpd服务

systemctl restart httpd



Centos7.6 http服务搭建全攻略的评论 (共 条)

分享到微博请遵守国家法律