当前位置: 首页 > news >正文

CentOS搭建Apache服务器

 安装对应的软件包

[root@hds ~]# yum install httpd mod_ssl -y

查看防火墙的状态和selinux

[root@hds ~]# systemctl status firewalld

[root@hds ~]# cat /etc/selinux/config

若未关闭,则关闭防火墙和selinux

[root@hds ~]# systemctl stop firewalld

[root@hds ~]# systemctl disable firewalld

Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.

Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@hds ~]# setenforce 0

[root@hds ~]# sed "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

启动httpd服务设为开机自启

[root@hds ~]# systemctl start httpd

[root@hds ~]# systemctl enable httpd

Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

创建三个网站根目录对应三种用户

[root@hds ~]# mkdir /www/8080 -p

[root@hds /]# mkdir /www/80

[root@hds /]# mkdir /www/ssl

配置根目录网站文件

[root@hds 80]# echo "welcome to 80" > skills80.html

[root@hds 8080]# echo "welcome to 8080" > skills8080.html

[root@hds ssl]# echo "welcome to ssl" > skillsssl.html

创建并配置网站:8080的访问控制文件和网站访问用户

[root@hds 8080]# vim .htaccess

authname "welcome to 8080"

#访问目录时的提示信息

authtype basic

#加密类型

authuserfile /www/8080

#存储访问网站用户的账号密码信息

require valid-user

#允许密码文件中的用户访问

[root@hds 8080]# htpasswd -cb .htpasswd webuser1 webuser1

Adding password for user webuser1

[root@hds 8080]# htpasswd -b .htpasswd webuser2 webuser2

Adding password for user webuser2

生成https的密钥和证书

cd /etc/pki/tls/private

[root@hds private]# openssl genrsa -out ca.key 2048

[root@hds private]# openssl req -x509 -new -key ca.key -out ca.crt -days 365

[root@hds private]# mv ca.crt ../certs/

 修改证书和密钥的位置

 [root@hds ~]# vim /etc/httpd/conf.d/ssl.conf

基于<VirtualHost _default_:443>该字段配置基于域名的虚拟主机

<VirtualHost _default_:443>

DocumentRoot "/www/ssl/"

ServerName www.hds.com

<Directory "/www/ssl/">

options all

AllowOverRide none

Require all granted

</Directory>

 配置8080和80的网站

[root@hds ~]# vim /etc/httpd/conf/httpd.conf 

Listen 80

<VirtualHost 192.168.126.166:80>

DocumentRoot "/www/80/"

ServerName www.hds.com

<Directory "/www/80/">

Options all

AllowOverRide none

Require all granted

</Directory>

</VirtualHost>

Listen 8080

<VirtualHost 192.168.126.166:8080>

DocumentRoot "/www/8080/"

ServerName www.hds.com

<Directory "/www/8080/">

Options all

AllowOverRide all

require all granted

</Directory>

</VirtualHost>

 

修改可以检索的网页文件

测试

 8080端口

 

443端口 

80端口 

http://www.lryc.cn/news/406830.html

相关文章:

  • CDGA|数据治理:安全如何贯穿数据供给、流通、使用全过程
  • 32单片机bootloader程序
  • MongoDB - 数组更新操作符:$、$[]、$pop、$pull、$push、$each、$sort、$slice、$position
  • 多GPU并行处理[任务分配、进程调度、资源管理、负载均衡]
  • 项目部署到服务器
  • Idea2024 创建Meaven项目没有src文件夹
  • LeetCode 2766.重新放置石块:哈希表
  • 基于STM32的农业大棚温湿度采集控制系统的设计
  • go语言的命名规则
  • 新增ClamAV病毒扫描功能、支持Java和Go运行环境,1Panel开源面板v1.10.12版本发布
  • Windows通过命令查看mac : getmac
  • Android笔试面试题AI答之Android系统与综合类(1)
  • 【Android】数据存储方案——文件存储、SharedPreferences、SQLite数据库用法总结
  • 抖音矩阵管理系统功能说明:一站式掌握
  • 旅游卡使用指南及常见疑问解答
  • 【MySQL篇】Percona XtraBackup标准化全库完整备份策略(第三篇,总共五篇)
  • 背单词工具(C++)
  • 面试八股 | 数据库引擎 | InnoDB和myISAM的区别?
  • GEE计算五种植被指数(NDVI、EVI2、RVI、MTVI2、OSAVI)
  • C/S架构和B/C架构
  • 音乐曲谱软件Guitar Pro 8.2 for Mac 中文破解版
  • 浅聊Web Storage(localStorage 和 sessionStorage)、cookie的使用场合
  • C语言输入输出缓冲机制
  • javaEE-03-cookie与session
  • EtherNet/IP转Profinet协议网关(经典配置案例)
  • 华为云依赖引入错误
  • 【Ubuntu】Ubuntu 配置镜像源(ARM)
  • 速腾聚创激光雷达复现FAST-LIO
  • k8s核心知识总结
  • 语言模型及数据集