Ken的杂谈
  • Ken的杂谈 (current)
  • 关于
  • 杂谈
    Java Spring Spring Boot Spring Cloud MyBatis C# .NET Core .NET ASP.NET Core ASP.NET ClassLibrary Mono 数据库 MySQL SQL Server 网络 缓存 Web Linux CentOS Ubuntu macOS Windows openEuler Nginx ServiceStack JS/JQ 正则 工具 IDE Grafana Exceptions CI/CD Solution 微服务 Arch Docker 杂谈
  • 系列
    Java 快速入门系列教程 Spring Boot 入门教程 Spring Boot 2.x 入门教程 Spring Cloud 入门教程 .NET Core 快速入门教程 ASP.NET Core 2.1 入门教程 CentOS 7 快速上手教程 Ubuntu快速上手入门教程 Hyper-V基础教程 Docker入门教程
  • GitHub

【CentOS7快速上手】2、Apache Server安装&配置

Linux CentOS @ 2017-06-29 22:32:53 · 阅读:(15968)

一、前言

  • 前置知识?
  1. vi命令:用来编辑文件;https://www.cnblogs.com/88999660/articles/1581524.html
  2. systemctl命令:服务操作;https://ken.io/note/centos-quickstart-basiccommand

二、安装

  • 1、 安装
yum install httpd
  • 2、 设置为开机启动&启用
systemctl enable httpd && systemctl start httpd
  • 3、 防火墙端口开放
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
  • 4、访问
http://ip
#/usr/share/httpd/noindex/index.html

三、Web应用/站点配置

  • 1、新建站点目录&index页面
#创建站点根目录
mkdir /var/www/web

#进入站点根目录并创建index.html
cd /var/www/web && vi index.html

#写入hello并保存即可,方便后续测试使用
  • 2、创建站点配置目录
mkdir /etc/httpd/sites
  • 3、修改默认配置
vi /etc/httpd/conf/httpd.conf

#增加项:
IncludeOptional /etc/httpd/sites/*.conf
  • 4、新建站点配置
vi /etc/httpd/sites/default.conf

#配置内容
<VirtualHost *:80>
    ServerName hello.html.com
    ServerAlias html.com
    DocumentRoot /var/www/web/
    ErrorLog /var/www/web/error.log
    CustomLog /var/www/web/requests.log combined
</VirtualHost>
  • 5、访问测试

本地修改hosts文件,把hello.html.com指向该CentOS服务器IP,然后通过该域名访问即可。

http://hello.html.com

  • 6、端口使用注意事项

1、虚拟机绑定的端口一定是Apache监听的端口
2、建议Apache使用81端口把80端口让给Nginx

四、备注

  • 相关阅读

Windows系统修改hosts文件:https://jingyan.baidu.com/article/b907e627d86be046e6891c41.html


  • 系列名称:CentOS 7 快速上手教程
  • 上一篇:【CentOS7快速上手】1、基础命令/常用命令
  • 下一篇:【CentOS7快速上手】3、FTP-Server部署

Ken的杂谈

本文由 ken.io 创作,采用CC BY 3.0 CN协议 进行许可。 可自由转载、引用、甚至修改,但需署名作者且注明出处。

Linux CentOS

随笔目录


    © Copyright 2012-2025 Ken的杂谈

    豫ICP备10025012号

    ASP.NET Core(6.0) on Linux