《Linux菜鸟入门2》Apache

●apache服务

1.什么是apache

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python解释器编译到服务器中。同时Apache音译为阿帕奇,是北美印第安人的一个部落,叫阿帕奇族,在美国的西南部。httpd是Apache超文本传输协议(HTTP)服务器的主程序

lamp=linux apache mysql php

lnmp=linux nginx mysql php

虽然nginx(nginx提供共享)性能更好,但是不是开源

相关命令

curl -I www.baidu.com(域名) 查看域名使用的信息

nmap 网络扫描

yum install nmap -y

nmap -A www.xupt.ed        在国外此命令违法

2.配置apache

①server端配置

hostnamectl set-hostname web1.westos.com

yum install httpd -y

cd /var/www/html/

systemctl start httpd

vim /etc/httpd/conf/httpd.conf

163 <IfModule dir_module>

164     DirectoryIndex index.html file

165 </IfModule>

在配置文件中,index.html和 file文件,哪个在前,在浏览器中优先看哪个,若都没有,则浏览器显示界面为apache测试页面

yum install httpd-manual.noarch -y  httpd使用手册

●更改默认发布目录:

将默认发布目录/var/www/html/改为/www/westos

[[email protected] ~]# cd /var/www/html/

[[email protected] html]# getenforce

Enforcing

[[email protected] html]# ls -Zd .

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 .

[[email protected] html]# mkdir /www/westos -p

[[email protected] html]# semanage fcontext -a -t httpd_sys_content_t ‘/www/westos(/.*)?‘

[[email protected] html]# restorecon -RvvF /www/

restorecon reset /www context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0

restorecon reset /www/westos context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0

[[email protected] html]# cd /www/westos/

[[email protected] westos]# vim index.html 编辑内容为/www/westos‘s page

[[email protected] westos]# vim /etc/httpd/conf/httpd.conf 修改内容为:

119 #DocumentRoot "/var/www/html"

120 DocumentRoot "/www/westos"

121 <Directory "/www/westos">

122        require all granted

123 </Directory>

[[email protected] westos]# systemctl restart httpd.service

在server浏览器中输入http://172.25.254.149  得到 /www/westos‘s page   表示更改成功

●端口:

[[email protected] westos]# ss -antlp | grep httpd

LISTEN     0      128                      :::80                      :::*

[[email protected] westos]# vim /etc/httpd/conf/httpd.conf

41 #Listen 12.34.56.78:80

42 Listen 80   默认为80端口

http://ip:80也可不加80一般默认

若改变为Listen 8080,则在浏览器中输入http://ip:8080

如:  http://172.25.254.149:8080

但8080端口容易被黑客利用攻击,慎用。

●访问权限黑白名单

[[email protected] westos]# vim /etc/httpd/conf/httpd.conf

120 DocumentRoot "/www/westos"

121 <Directory "/www/westos">

122        require all granted

123        Order Deny,Allow    **谁在前,先读谁,一般Allow在前

124        Allow from 172.25.254.0/24  **允许172.25.254.x网段所有人访问

125        Deny from ALL   **拒绝所有人访问

126 </Directory>

[[email protected] westos]# systemctl restart httpd.service

●设置用户访问权限

vim /etc/httpd/conf/httpd.conf

121 <Directory "/www/westos">

122        Require all granted

123        AllowOverride all

124        Authuserfile /etc/httpd/htpasswdfile   用户信息所在文件

125        Authname "Please input username and password"  提示信息

126        Authtype basic    基本认证类型

127        Require user admin    只允许使用用户admin在浏览器中访问

128 </Directory>

systemctl restart httpd.service

若要所以用户都可访问则:

vim /etc/httpd/conf/httpd.conf

127        Require valid-user

systemctl restart httpd.service

访问需要输入用户和密码

●apaache的虚拟主机

vim /etc/httpd/conf/httpd.conf先修改为初始状态

119 DocumentRoot "/var/www/html"

120 #DocumentRoot "/www/westos"

121 #

122 # Relax access to content within /var/www.

[[email protected] westos]# cd /etc/httpd/

[[email protected] httpd]# ls

conf  conf.d  conf.modules.d  logs  modules  run

[[email protected] httpd]# htpasswd -cm htpasswdfile admin   -c表示建立

New password:

Re-type new password:

Adding password for user admin

[[email protected] httpd]# htpasswd -m htpasswdfile westos  第二次新建不用加c,若加-c会覆盖第一次建立的用户信息

New password:

Re-type new password:

Adding password for user westos

[[email protected] httpd]# cat htpasswdfile

admin:$apr1$JICcD90s$CUjJyhcTEEHIz5x1qj55z1

westos:$apr1$6rk8RbXl$CIFniY0.TwqKr.oY.tvCg1

[[email protected] httpd]# vim /etc/httpd/conf/httpd.conf

[[email protected] httpd]# ll /etc/httpd/htpasswdfile

-rw-r--r--. 1 root root 89 Dec  8 01:17 /etc/httpd/htpasswdfile

vim /etc/httpd/conf/httpd.conf

[[email protected] httpd]# systemctl restart httpd.service

[[email protected] httpd]# cd /var/www/html/

[[email protected] html]# ls

index.html

[[email protected] html]# vim index.html  这里是默认的

[[email protected] html]# mkdir /var/www/virtual/news.westos.com/html -p

[[email protected] html]# mkdir /var/www/virtual/music.westos.com/html -p

[[email protected] html]# cd /var/www/virtual/news.westos.com/html/

[[email protected] html]# vim index.html

[[email protected] html]# cd /var/www/virtual/music.westos.com/html/

[[email protected] html]# vim index.html

[[email protected] html]# cd /etc/httpd/conf.d/

[[email protected] conf.d]# ls

autoindex.conf  manual.conf  README  userdir.conf  welcome.conf

[[email protected] conf.d]# vim /etc/httpd/conf/httpd.conf

[[email protected] conf.d]# vim default.conf

[[email protected] conf.d]# vim music.conf

[[email protected] conf.d]# vim news.conf

[[email protected] conf.d]# ls

autoindex.conf  manual.conf  news.conf  userdir.conf

default.conf    music.conf   README     welcome.co

[[email protected] conf.d]# systemctl restart httpd

vim /etc/httpd/conf/httpd.conf                查看文件应该编辑的地方

353 IncludeOptional conf.d/*.conf

[[email protected] named]# vim /etc/hosts 测试端:(在desktop上)

172.25.254.112 www.westos.com westos.com news.westos.com music.westos.com

firefox -->在浏览器中输入不同的域名

如果显示对应 ,则配置正确

时间: 2024-08-04 13:57:57

《Linux菜鸟入门2》Apache的相关文章

《Linux菜鸟入门2》系统恢复和selinux &nbsp;

selinux的初级管理 1.什么是selinux Selinux:内核级加强型防火墙 2.如何管理selinux级别 selinux开启或者关闭 vim /etc/sysconfig/selinux selinux=disabled   关闭状态 selinux=Enforcing   强制状态 selinux=Permissive   警告状态 getenforce       查看状态 当selinux开启时 setenforce 0|1   更改selinux运行级别 3.如何更改文件安

《Linux菜鸟入门》初识linux基础

初识linux 一  进入系统 1.用户 普通用户 : student 密码: student 超级用户 : 点击 not listed username :root   password: redhat 在系统中,为了系统的安全性,大部分使用的是普通用户. 2.语言调整 点击屏幕左上 Application  点击 system tools  setting  Region&language 3.系统的基础使用 1>系统登陆 图形登陆方式:即有画面的登陆方式 文本登陆方式:在终端方式下登陆

《Linux菜鸟入门》认识linux系统

系统文件管理 一 linux系统结构 linux系统和windows系统的区别在表面上是类似于ios操作系统和Android的区别,linux系统的存储是基于根目录的,不同于windows系统的分盘.在linux中,所有东西的存在形式都是以文件形式存在,因此,首先要了解的就是linux的系统结构: linux是一个倒树结构,所有的文件都是在系统的顶级目录下的,即根目录"/",而在"/"下的二级目录都是系统装机的时候系统自己建立的,而这些二级目录都有相应的功能: /b

《Linux菜鸟入门2》空壳邮件服务

●空壳邮件 1.引入空壳邮件的意义 邮件服务器直接暴露在网络环境下安全性会大大降低,所以引入"空壳服务器"是为了保证真正服务器的安全,空壳服务器的功能就是将受到的邮件转发(双向的). 2.制作空壳邮件 在配置好DNS的前提下: 空壳服务器配置(maillinux.linux.com): vim /etc/named.rfc1912.zones cd /var/named/ cp -p westos.com.zone westos.org.zone vim westos.org.zone

《Linux菜鸟入门2》设备分区及磁盘管理

第四单元   设备分区及磁盘管理 ● 分区方式 fdisk  /dev/vdb                        划分命令/dev/vdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): m  

《Linux菜鸟入门》设备相关信息

linux中设备的访问 1.设备识别 /dev/xdxn      硬盘设备 /dev/sda1 /dev/cdrom /dev/mapper/*  虚拟设备 2.设备的使用 设备发现 fdisk -l               查看真实存在的设备 cat /proc/partitions   系统能够识别的设备 blkid                  系统能够挂载的使用设备 df -h(H)              查看设备被系统使用的情况 设备的使用 ①.设备的挂载 mount  

《Linux菜鸟入门2》mariadb服务

学会使用mariadb数据库 1.yum search mariadb                    查询自己要装的包 2.yum install mariadb-server.x86_64 -y           安装服务3.netstat -antlpe | grep mysql                查看接口回环接口为127.0.0.1 vim /etc/my.cnf                      配置接口 Skip=networking=1 Log=arro

《Linux菜鸟入门2》mail服务

配置DNS mailwestos.example.com vim /etc/named.rfc1912.zones zone "westos.com" IN { type master; file "westos.com.zone"; allow-update { none; }; }; zone "linux.com" IN { type master; file "linux.com.zone"; allow-update

《Linux菜鸟入门》Linux的用户

理解用户 1.用户定义: 用户就是系统使用者的身份,在系统中,用户存储为若干字符串+若干个系统配置文件 举例: 用户信息涉及到的系统配置文件 /etc/passwd    用户信息 用户:密码:uid:gid:说明:家目录:用户使用的shell /etc/shadow    用户认证信息 用户:密码:最后一次密码修改时间:最短有效期:最长有效期:警告期:非活跃期:帐号到期日 /etc/group     组信息 组名称:组密码:组id:附加组成员 /etc/gshadow    组认证信息 /h