httpd服务

文章目录

1、搭建一个网络yum源

bash 复制代码
[root@test01 conf.d]# cat repo.conf 
<virtualhost *:80>
  documentroot /var/www/html/
  ServerName 10.104.43.154
  alias /repo /var/www/html/repo  # 使用alias指令来进行指定访问repo的时候访问到/var/www/html/repo这个里面
</virtualhost>
<directory /var/www/html/repo>
  require all granted
  Options Indexes FollowSymLinks
</directory>
<FilesMatch "\.(iso|img)$">
    Require all denied
</FilesMatch>

2、基于域名访问的虚拟主机

  • 通过访问域名来访问对应的内容
bash 复制代码
# 创建访问网页的内容
[root@test01 share]# tree ./apache
./apache
├── a
└── b

2 directories, 0 files

[root@test01 apache]# echo "welcome a.com" > a/index.html
[root@test01 apache]# echo "welcome b.com" > b/index.html

# 编写配置文件
[root@test01 conf.d]# cat a.conf b.conf 
<Virtualhost *:80>
  Documentroot /share/apache/a
  ServerName www.a.com
</virtualhost>
<Directory /share/apache/a>
  require all granted
</Directory>
<Virtualhost *:80>
  Documentroot /share/apache/b
  ServerName www.b.com
</virtualhost>
<Directory /share/apache/b>
  require all granted
</Directory>

# 安全放行
[root@test01 /]# firewall-cmd --permanent --add-service=http
[root@test01 /]# firewall-cmd --reload 
success

# 自定义的目录需要给予上下文
[root@test01 share]# semanage fcontext -a -t httpd_sys_content_t './apache(/.*)?'
[root@test01 share]# restorecon -RFv ./apache/
restorecon reset /share/apache context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
restorecon reset /share/apache/a context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
restorecon reset /share/apache/a/index.html context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
restorecon reset /share/apache/b context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
restorecon reset /share/apache/b/index.html context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0


# 进行访问
# 重启服务
[root@test01 conf.d]# systemctl restart httpd

[root@test02 ~]# curl www.a.com
welcome a.com
[root@test02 ~]# curl www.b.com
welcome b.com

3、基于端口来访问+域名

bash 复制代码
# 配置文件
[root@test01 conf.d]# cat a.conf 
Listen 8088
<Virtualhost *:8088>
  Documentroot /share/apache/a
  ServerName www.a.com
</virtualhost>
<Directory /share/apache/a>
  require all granted
</Directory>

# 添加端口
[root@test01 conf.d]# semanage port -a 8088 -t http_port_t -p tcp
[root@test01 conf.d]# semanage port -l | grep 8088
http_port_t                    tcp      8088, 80, 81, 443, 488, 8008, 8009, 8443, 9000
# 重启服务
[root@test01 conf.d]# systemctl restart httpd

# 安全放行
[root@test01 conf.d]# firewall-cmd --permanent --add-port=8088/tcp
success
[root@test01 conf.d]# firewall-cmd --reload
success

# 访问
[root@test02 ~]# curl www.a.com:8088
welcome a.com
[root@test02 ~]# curl www.b.com:8089
welcome b.com

4、搭建个人网站

bash 复制代码
# 修改user.conf文件 
UserDir enabled
UserDir public_html


# 创建个人网站文件
[root@test01 q7]# tree public_html/
public_html/
└── index.html

0 directories, 1 file
[root@test01 q7]# ll -Z public_html/
-rw-r--r--. root root unconfined_u:object_r:httpd_user_content_t:s0 index.html

# 安全放行
[root@test01 q7]# setsebool -P httpd_enable_homedirs on
# 权限放行
[root@test01 q7]# ll -d
drwx--x--x. 3 q7 q7 81 Sep 27 11:35 .

# 访问
http://10.104.43.154/~q7/

5、加密访问+显示自定义网页内容

bash 复制代码
# 安装加密的包
[root@test01 q7]# yum -y install mod_ssl

# 生成私钥
openssl genrsa > tlsweb.key

# 生成一个证书请求文件
openssl req -new -key tlsweb.key > tlsweb.csr

#  生成一个证书文件
openssl req -x509 -days 365 -in tlsweb.csr -key tlsweb.key > tlsweb.crt

# 将生成的私钥和证书文件移动到指定的路径
[root@test01 tls]# pwd
/etc/pki/tls
cp /root/tlsweb.key ./private/
cp /root/tlsweb.crt certs/

firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload

# 网页内容
[root@test01 conf.d]# cat a.conf 
<Virtualhost *:443>
  Documentroot /share/apache/a
  ServerName www.a.com
  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/tlsweb.crt
  SSLCertificateKeyFile /etc/pki/tls/private/tlsweb.key
</virtualhost>
<Directory /share/apache/a>
  require all granted
</Directory>


[root@test01 conf.d]# systemctl restart httpd
# https访问
相关推荐
忙碌的菠萝6 分钟前
使用Apache Lucene构建高效的全文搜索服务
apache·mybatis·lucene
likfishdn20 分钟前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean40 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=42 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙2 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
北京耐用通信2 小时前
航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
运维·机器人·自动化
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net