系统相关
首页 > 系统相关> > linux 学习第十四天(Apache安装、基于ip、基于域名、基于端口配置)

linux 学习第十四天(Apache安装、基于ip、基于域名、基于端口配置)

作者:互联网

一、虚拟主机

A、基于IP地址  B、基于域名  C、基于端口号

 

复习yum仓库挂载

mkdir /media/cdrom

mount /dev/cdrom /media/cdrom/

vim /etc/fstab

/dev/cdrom /media/cdrom iso9960 defaults 0 0

 

vim /etc/yum.repos.d/rhel7.repo

 

yum install httpd

systemctl restart httpd

systemctl enable httpd

 

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

systemctl restart network

 

基于IP地址

 

 

mkdir -p /home/wwwroot/10

mkdir -p /home/wwwroot/20

mkdir -p /home/wwwroot/30

echo "1111111" > /home/wwwroot/10/index.html

echo "2222222" > /home/wwwroot/20/index.html

echo "3333333" > /home/wwwroot/30/index.html

 

vim /etc/httpd/conf/httpd.conf

 

 

systemctl restart httpd

 

ls -lZd /var/www/html/

semanage fcontext -at httpd_sys_content_t /home/wwwroot

semanage fcontext -at httpd_sys_content_t /home/wwwroot/10

semanage fcontext -at httpd_sys_content_t /home/wwwroot/20

semanage fcontext -at httpd_sys_content_t /home/wwwroot/30

semanage fcontext -at httpd_sys_content_t /home/wwwroot/10/*

semanage fcontext -at httpd_sys_content_t /home/wwwroot/20/*

semanage fcontext -at httpd_sys_content_t /home/wwwroot/30/*

 

restorecon -Rv /home/wwwroot/

基于域名

mkdir -p /home/wwwroot/www

mkdir -p /home/wwwroot/bbc

mkdir -p /home/wwwroot/tech

 

echo "wwwwwwwww" > www/index.html

echo "bsbbbbbsbs" > bbs/index.html

echo "techtechtech" > tech/index.html

 

vim /etc/hosts

 

ls -lZd /var/www/html  (查看默认网站下权限)

添加基于域名虚拟主机权限

semanage fcontext -at httpd_sys_content_t /home/wwwroot

semanage fcontext -at httpd_sys_content_t /home/wwwroot/www

semanage fcontext -at httpd_sys_content_t /home/wwwroot/www/*

semanage fcontext -at httpd_sys_content_t /home/wwwroot/bbc

semanage fcontext -at httpd_sys_content_t /home/wwwroot/bbc/*

semanage fcontext -at httpd_sys_content_t /home/wwwroot/tech

semanage fcontext -at httpd_sys_content_t /home/wwwroot/tech/*

 

restorecon -Rv /home/wwwroot/  (使配置生效)

 

 

 

基于端口号

 

mkdir -p /home/wwwroot/8555

mkdir -p /home/wwwroot/8666

echo "8555555555555" > /home/wwwroot/8555/index.html

echo "8666666666666" > /home/wwwroot/8666/index.html

 

 

 

semanage port -l | grep http  (查看关于httpd服务相关端口号)

 

semanage port -at http_port_t -p tcp 8555

semanage port -at http_port_t -p tcp 8666

 

systemctl restart httpd

systemctl enable httpd

 

ls -lZd /var/www/html

semanage fcontext -at httpd_sys_content_t /home/wwwroot

semanage fcontext -at httpd_sys_content_t /home/wwwroot/8555

semanage fcontext -at httpd_sys_content_t /home/wwwroot/8555/*

semanage fcontext -at httpd_sys_content_t /home/wwwroot/8666

semanage fcontext -at httpd_sys_content_t /home/wwwroot/8666/*

restorecon -Rv /home/wwwroot/

 

Apache访问控制

 

yum install httpd

systemctl restart httpd

systemctl enable httpd

iptables -F

service iptables save

echo "weclcom to rise-house" > /var/www/html/server/index.html

 

systemctl restart httpd

 

标签:httpd,基于,semanage,ip,wwwroot,content,第十四天,fcontext,home
来源: https://www.cnblogs.com/rise-home/p/10588722.html