1 Web简略了解

  • Web服务器称为WWW服务器,首要是供给上网功用;
  • 常见的Web服务器有:Microsoft IISIBM WebSphereApacheTomcat等;
  • 本文首要以Apache服务器为例了解一些Linux/centos上怎么装备管理Web服务器。

2 关于Apache

  • Apache是一种开源的Web服务器软件;
  • 具有跨渠道特性,支撑UnixLinuxBSD等操作系统;
  • 支撑静态和动态内容;
  • 对于模块化支撑;
  • 支撑SSL和虚拟主机;
  • 具有完整的日志功用;
  • 支撑用户认证机制等。

3 怎么装置Apache服务器?

3.1 Apache服务装置

  • 先检查系统上是否现已装置了Apache服务,如下:
rpm -qa | grep httpd
  • 我的是现已装置了如下:
    Linux/centos上怎么装备管理Web服务器?
  • 如果没有装置,能够运用以下指令装置:
yum -y install httpd

3.2 httpd服务的基本操作

  • 检查httpd服务的运转状态:
systemctl status httpd.service
  • 如下显示,我的还没有启动:
    Linux/centos上怎么装备管理Web服务器?
  • 启动httpd服务:
systemctl start httpd.service
  • 启动后如下显示:
[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-11-08 17:53:21 CST; 2s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 5953 (httpd)
   Status: "Processing requests..."
    Tasks: 9
   CGroup: /system.slice/httpd.service
           ├─5953 /usr/sbin/httpd -DFOREGROUND
           ├─5954 /usr/libexec/nss_pcache 6 off
           ├─5956 /usr/sbin/httpd -DFOREGROUND
           ├─5958 /usr/sbin/httpd -DFOREGROUND
           ├─5959 /usr/sbin/httpd -DFOREGROUND
           ├─5960 /usr/sbin/httpd -DFOREGROUND
           ├─5961 /usr/sbin/httpd -DFOREGROUND
           └─5962 /usr/sbin/httpd -DFOREGROUND
Nov 08 17:53:20 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Nov 08 17:53:20 localhost.localdomain httpd[5953]: AH00558: httpd: Could not reliably determine the server's fully qualified domain na...message
Nov 08 17:53:21 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
  • 中止httpd服务:
systemctl stop httpd.service
  • 重启httpd服务:
systemctl restart httpd.service
  • 设置开机自启动:
systemctl enable httpd.service
  • 检查设置自启动是否成功:
systemctl list-unit-files | grep httpd
  • 如下显示则为设置成功了:
    Linux/centos上怎么装备管理Web服务器?

4 怎么装备Apache服务器?

4.1 关于httpd.conf装备

  • Apache服务的装备文件为httpd.conf,文件在`/etc/httpd/conf/下:
    Linux/centos上怎么装备管理Web服务器?
  • httpd.conf文件内容说明:
内容 说明
#ServerRoot 全局环境设置
#Main serve rconfiguration 主服务器设置
虚拟主机设置

4.2 常用指令

指令 说明 示例
ServerName 设置Apache服务器的主机名和端口号 ServerName www.noamanelson.com 80
ServerRoot 设置Apache服务器的根目录,包括conf、logs、modules等子目录 ServerRoot /etc/httpd
Listen 设置Apache服务器的监听端口,默许监听80,一般在监听非80时会设置 Listen 8088
DocumentRoot 设置Apache供给的HTML文档根目录 ,默许为/var/www/html DocumentRoot /www/myweb
Directory 指定Apache服务器根目录的拜访权限和方法 <Directory "/var/www">AllowOverride None Require all granted </Directory >
DirectoryIndex 设置Apache服务器网站的主文件,一般为index.html DirectoryIndex index.html
VirtualHost 设置特定虚拟主机 <VirtualHost 192.168.1.7> DocumentRoot /www/myweb ServerName noamanelson.com </VirtualHost>
ServerAdmin 设置管理员邮箱 ServerAdmin admin@noamanelson.com
TimeOut 设置接收和发送数据时的超时时间 TimeOut 100
ErrorLog 指定Apache服务器运用的错误日志文件 ErrorLog logs/error_log
CustomLog 指定Apache服务器运用的拜访日志 /
Include 其他装备文件 /

5 简略实例

  • 首要方针是装备个人Web站点;
  • 建用户NoamaNelson,修改权限,并树立目录public_html:
    Linux/centos上怎么装备管理Web服务器?
useradd NoamaNelson
mkdir /home/NoamaNelson/public_html
chmod  711 /home/NoamaNelson/
chmod  755 /home/NoamaNelson/public_html/
  • public_html下树立网页文件index,html:
vim /home/NoamaNelson/public_html/index.html
Welcome everyone,
This is my Web~~~
  • 装备/etc/httpd/conf.d/userdir.conf文件:
<IfModule mod_userdir.c>
    #UserDir disabled
    UserDir public_html
</IfModule>
<Directory "/home/*/public_html">
    AllowOverride FileInfo AuthConfig Limit Indexes
    #Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Options None
    Require method GET POST OPTIONS
</Directory>
    Require method GET POST OPTIONS
  • 保存以上文件,重启服务器,关闭防火墙,将Selinux设置为Permissive
    Linux/centos上怎么装备管理Web服务器?
systemctl start httpd
systemctl stop firewalld.service
setenforce 0
getenforce
  • 在浏览器中输入服务ip/ ~NoamaNelson/即可打开NoamaNelson的个人主页,比方我的是如下:
    Linux/centos上怎么装备管理Web服务器?
http://172.28.18.146/~NoamaNelson/