码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Linux之httpd及虚拟主机的配置及使用


    目录

    1.安装httpd,并将访问apache服务器的首页修改为hello.html 且内容为: "My Home Page is hello"

    1.安装httpd

    2.查看服务器首页

     3.修改服务器显示首页

    4.修改首页内容

     2.虚拟主机:虚拟两台主机ip为120,121, 对应访问目录:/www/ip/100, /www/ip/200

     1.首先在连接上添加两个IP,然后重启链接

    2. 创建对应目录

    3.在对应文件中配置

    创建首页文件index.html 

    ​3.配置不同端口的虚拟主机访问apache服务器

    1.创建目录/www/port/{9090,9091}

    2.在对应目录中创建文件并设置主页内容 

     3.在下面路径中vim创建并配置文件

    4.重启httpd服务

    5.效果如下 


    1.安装httpd,并将访问apache服务器的首页修改为hello.html 且内容为: "My Home Page is hello"

    1.安装httpd

    2.查看服务器首页

    默认显示首页内容的文件为/var/www/html/下面的index.html

    1. [root@rhcsa ~]# cd /var/www/html/
    2. [root@rhcsa html]# ll
    3. total 132
    4. -rw-r--r--. 1 root root 12 Jul 26 11:21 index.html
    5. -rw-r--r--. 1 root root 17892 May 20 2021 LICENSE
    6. -rw-r--r--. 1 root root 31040 Jan 19 2021 qqqun.png
    7. drwxr-xr-x. 2 root root 124 May 20 2021 readme
    8. -rw-r--r--. 1 root root 71156 May 20 2021 readme.html
    9. drwxr-xr-x. 13 root root 4096 May 20 2021 upload
    10. drwxr-xr-x. 4 root root 94 May 20 2021 utility
    11. [root@rhcsa html]# more index.html
    12. hello world

     3.修改服务器显示首页

    1. [root@rhcsa html]# mv index.html hello.html
    2. [root@rhcsa html]# ll
    3. total 132
    4. -rw-r--r--. 1 root root 12 Jul 26 11:21 hello.html
    5. -rw-r--r--. 1 root root 17892 May 20 2021 LICENSE
    6. -rw-r--r--. 1 root root 31040 Jan 19 2021 qqqun.png
    7. drwxr-xr-x. 2 root root 124 May 20 2021 readme
    8. -rw-r--r--. 1 root root 71156 May 20 2021 readme.html
    9. drwxr-xr-x. 13 root root 4096 May 20 2021 upload
    10. drwxr-xr-x. 4 root root 94 May 20 2021 utility
    11. [root@rhcsa html]# more hello.html
    12. hello world

    4.修改首页内容

    [root@rhcsa html]# vim hello.html 
    

    1. [root@rhcsa html]# more hello.html
    2. My Home Page is hello

     然后在配置文件中修改默认打开文件为hello.html

    [root@rhcsa conf]# vim httpd.conf
    

     重启httpd服务

    [root@rhcsa conf]# systemctl restart httpd
    

     

     2.虚拟主机:虚拟两台主机ip为120,121, 对应访问目录:/www/ip/100, /www/ip/200

     1.首先在连接上添加两个IP,然后重启链接

    1. [root@rhcsa 200]# nmcli connection modify ens224 +ipv4.addresses 192.168.40.120/24
    2. [root@rhcsa 200]# nmcli connection modify ens224 +ipv4.addresses 192.168.40.121/24
    3. [root@rhcsa 200]# nmcli c up ens224

    2. 创建对应目录

    [root@rhcsa ~]# mkdir /www/ip/{100,200} -p

    3.在对应文件中配置

    绝对路径:/etc/httpd/conf.d/

    建立myhosts.conf文件,在里面配置


    创建首页文件index.html 

    1. [root@rhcsa 100]# echo hello world! > index.html
    2. [root@rhcsa 200]# echo hello world!! > index.html


    3.配置不同端口的虚拟主机访问apache服务器

    1.创建目录/www/port/{9090,9091}

    [root@rhcsa www]# mkdir port/{9090,9091} -p

    2.在对应目录中创建文件并设置主页内容 

    1. [root@rhcsa conf.d]# echo hello world9090 > /9090/index.html
    2. [root@rhcsa conf.d]# echo hello world9091 > /9091/index.html

     3.在下面路径中vim创建并配置文件

    [root@rhcsa conf.d]# vim /etc/httpd/conf.d/myhosts2.conf

    4.重启httpd服务

    [root@rhcsa conf]# systemctl restart httpd
    

    5.效果如下 

     

     

  • 相关阅读:
    基于C语言实现的顾客排位与桌位安排系统
    @RabbitListener和@RabbitHandler的使用
    【项目_01】搭建项目基本框架、底部tabbar、头部banner | 旅途拾景 | 基于Vue3全家桶
    【rtp-benchmarks】对接发送侧,实现基于uvgRtp的多线程接收
    Linux环境配置jdk
    Android Studio下运行java main 方法
    站长号平台新版友情链接交换上线
    # 02 初识Verilog HDL
    原生小程序小话题——自定义组件1
    编写X86的ShellCode
  • 原文地址:https://blog.csdn.net/weixin_64051859/article/details/125998813
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号