linux命令:httpd 安装配置 elinks htpasswd


LAMP:L=linux  A=apache网页服务器  M=mysql数据库服务器  P=php应用服务器


httpd: 

事先创建进程,按需维持适当的进程,模板化设计,核心比较小,各种功能都模块添加,

支持运行配置,支持单独编译模块。

 

httpd -t用于检测httpd.conf主配置文档是否存在语法错误 

[[email protected] conf]# httpd -t

Syntax OK       检测配置文档语法正常

elinks:linux系统中打开纯文本网页界面。

  参数:

      -dump   打开纯文本界面后直接退出不进入交互模式

-source  打开网页的源代码

[[email protected] conf]# elinks -source 10.109.134.249

<html>  <head>test</head> <title>testtest</title>

<body>

haha test

</body> </html>

htpasswd 生成访问网页用户所需的密码文件

  参数:

     -c:第一次创建密码文本文件需加此项,表示新建,密码文本存在后不能加-c选项,否则密码文        本文件会被重新建立并替换以前的文本文件。

-m:表示密码以md5加密格式存放在密码文本中

-D:表示删除htpasswd中的用户

[[email protected] conf]# htpasswd -c -m /etc/httpd/conf/htpasswd hadoop

New password:

Re-type new password:

Adding password for user hadoop

[[email protected] conf]# htpasswd -m /etc/httpd/conf/htpasswd tom

New password:

Re-type new password:

Adding password for user tom

[[email protected] conf]# cat htpasswd

hadoop:$apr1$8yVMk/..$8xI.A4UmnNWHuXZfB5fVD.

tom:$apr1$miCJM/..$DNbL8QzsOR6W7cx1vOHll.

[[email protected] conf]# htpasswd -D /etc/httpd/conf/htpasswd tom

Deleting password for user tom

[[email protected] conf]# cat /etc/httpd/conf/htpasswd

hadoop:$apr1$8yVMk/..$8xI.A4UmnNWHuXZfB5fVD.

   

httpd安装和配置(事先让selinux处于permssive,disabled):rpm包安装、源码包编译安装

   httpd:   /usr/sbin/httpd(MPM:prefork)

/etc/rc.d/init.d/httpd:httpd服务脚本  port:(80/tcp);(ssl:443/tcp)

/etc/httpd/:工作根目录,相当于程序安装目录

/etc/httpd/conf/:配置文件目录

主配置文件:/etc/httpd/conf/httpd.conf

/etc/httpd/conf.d/*.conf也是属于主配置文件中的

/etc/httpd/modules/:模块目录

/etc/httpd/logs/ --> /var/log/httpd/:日志目录

日志文件有两类:访问日志access_log,错误日志:err_log

/var/www/:网页页面存放目录

/var/www/html/:静态网页存放目录

/var/www/cgi-bin:动态网页存放目录

一、httpd安装:

[[email protected] ~]# yum -y install httpd

[[email protected] ~]# rpm -ql httpd  查看httpd安装的目录

/etc/httpd

/etc/httpd/conf

/etc/httpd/conf.d

/etc/httpd/conf.d/README

/etc/httpd/conf.d/proxy_ajp.conf

/etc/httpd/conf.d/welcome.conf

[[email protected] ~]#service httpd start 启动httpd进程

[[email protected] ~]# netstat -tlnp |grep :80  查看httpd进程端口

tcp    0    0 :::80     :::*          LISTEN      4222/htt

[[email protected] ~]# ps aux |grep httpd 查看httpd启动的进程

root      4222  0.0  1.2 236100 11204 ?        Ss   10:01   0:00 /usr/sbin/httpd

apache    4224  0.0  0.8 236236  7292 ?        S    10:01   0:00 /usr/sbin/httpd

apache    4225  0.0  0.8 236236  7224 ?        S    10:01   0:00 /usr/sbin/httpd

apache    4226  0.0  0.8 236236  7244 ?        S    10:01   0:00 /usr/sbin/httpd

apache    4227  0.0  0.8 236236  7252 ?        S    10:01   0:00 /usr/sbin/httpd

apache    4228  0.0  0.8 236236  7244 ?        S    10:01   0:00 /usr/sbin/httpd

apache    4229  0.0  0.8 236236  7244 ?        S    10:01   0:00 /usr/sbin/httpd

apache    4230  0.0  0.7 236236  6636 ?        S    10:01   0:00 /usr/sbin/httpd

apache    4231  0.0  0.7 236236  6632 ?        S    10:01   0:00 /usr/sbin/httpd

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

[[email protected] httpd]# tree conf.d/

conf.d/

|-- README

|-- manual.conf

|-- perl.conf

|-- php.conf

|-- proxy_ajp.conf

|-- python.conf

|-- squid.conf

|-- ssl.conf

|-- webalizer.conf

`-- welcome.conf   默认httpd网页显示内容/etc/httpd/conf.d/welcome.conf


二、httpd配置:

配置文档路径:/etc/httpd/conf/httpd.conf   配置文档分三个部分

[[email protected] conf]# grep "Section" httpd.conf

### Section 1: Global Environment   全局环境段

### Section 2: ‘Main‘ server configuration  主服务器段

### Section 3: Virtual Hosts   虚拟主机段

*第2部分与第3部分不能同时生效.(默认启用主服务器配置)

http:指令不区分字符大小写,value则根据需求有可能要区分大小写

以#开头后直接接字符的表示可以启用段,以# 开头且后跟空格后再接字符表示纯注释段

配置文件由2部分组成:   directive(指令)   value(值)

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

全局环境段解析:

--------------------------------------------------------------------------

#

# This is the main Apache server configuration file.  It contains the

# configuration directives that give the server its instructions.

# See <URL:http://httpd.apache.org/docs/2.2/> for detailed information.

# In particular, see

# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>

# for a discussion of each configuration directive.

#

ServerTokens  OS

指令     值

Timeout   120         #超时时间(秒)

KeepAlive   Off         #是否开启常链接

MaxKeepAliveRequests   100  #保持常连接的数量0为无限制

KeepAliveTimeout  15      #保持常连接的时间(秒)

<IfModule prefork.c>

StartServers       8 #服务器一开启就启动8个空闲进程

MinSpareServers     5 #至少保证5个空闲进程接收用户请求

MaxSpareServers     20 #最大空闲进程数,超过该数值直接结束其他空闲进程

ServerLimit      256 #该项限制用户最大请求数,如需提高接收用户最大请求数,必须先关闭           httpd服务进程后再把该数值提高,并把MaxClients数值提高,重启服务进程才生效。

MaxClients        256 #接收用户的最大请求数

MaxRequestsPerChild  4000 #一个进程最多响应请求数,超过该数字,该进程将直接被强制结束

</IfModule>

<IfModule worker.c>

StartServers       2  #服务器一开启就启动2个空闲进程数

MaxClients        150 #接收用户的最大请求数

MinSpareThreads     25  #最小空闲线程数(所有进程一起的线程数)

MaxSpareThreads     75  #最大空闲线程数(所有进程一起的线程数)

ThreadsPerChild     25  #每个进程生成多少个线程数

MaxRequestsPerChild  0   #没一个进程响应多少个请求,因为是通过线程响应所以这里没做限制

</IfModule>

Listen 80      #指定监听端口

Listen 192.168.1.10:8080   #指定监听特定IP的端口

Include conf.d/*.conf    #/etc/httpd/conf.d/*.conf所有文件都嵌入到该配置文档中

User apache     #默认用户

Group apache    #默认用户组

------------------------------------------------------------------------------------

主服务器段各选项的解析:

ServerAdmin [email protected]   #管理员邮箱

#ServerName 192.168.1.100:80 #服务器主机名称

DocumentRoot "/var/www/html" #文档根目录,存放网页文档的路径

Options Indexes FollowSymLinks #Indexes:允许索引目录 ;FollowSymLinks:允许访问符号链接指向的原文件;Includes:允许执行服务端包含(SSI)脚本;none:不支持任何选项;all:支持所有选项

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

#   Options FileInfo AuthConfig Limit

AllowOverride None #是否允许覆盖控制规则,AllowOverride有几个选项 All,None,AuthConfig

(AllowOverride AuthConfig  执行下面的Auth控制规则

AuthType Basic     规则类型

AuthName "Restricted Site..."   规则名称

AuthUserFile "/etc/httpd/conf/htpasswd"  需要该文本中的密码设置才能访问,如何建立密码文本                              请参考本文前部分htpasswd命令使用方法。

Require valid-user   valid-user表示htpasswd文档中的所有用户都能访问,如果只是允许文档中                 一部分用户访问,则需要配置 Require user username

Order allow,deny  #order用于定义基于主机的访问功能的,IP,网络地址或主机定义访问控制机制

Allow from all    #运行所有主机访问

地址的表示方式:IP:192.168.0.0/16  hostname:www.a.com  domainname:john.com

Usage:

1、仅允许192.168.0.0/24主机段访问

Order allow,deny

Allow from 192.168.0.0/24

2、拒绝172.16.100.177 192.168.0.1主机访问

Order deny,allow

Deny from 172.16.100.177 192.168.0.1

实例:设置访问网页需要通过用户名和密码访问

[[email protected] conf]# htpasswd -c -m /etc/httpd/conf/htpasswd hadoop   #首先生成密码文件

New password:

Re-type new password:

Adding password for user hadoop

[[email protected] conf]# htpasswd -m /etc/httpd/conf/htpasswd tom

New password:

Re-type new password:

Adding password for user tom

[[email protected] conf]# cat ht

htpasswd         httpd.conf       httpd.conf.back

[[email protected] conf]# cat htpasswd

hadoop:$apr1$8yVMk/..$8xI.A4UmnNWHuXZfB5fVD.

tom:$apr1$miCJM/..$DNbL8QzsOR6W7cx1vOHll.

[[email protected] conf]# vim httpd.conf    #修改配置文件,基于用户认证

[[email protected] conf]# httpd -t   #检查配置文件是否有语法错误

Syntax OK

[[email protected] conf]# service httpd restart       #重启服务进程

停止 httpd:                                               [确定]

启动 httpd:                                               [确定]

再访问该站点时,提示输入用户名和密码:

输入htpasswd密码文本中的正确用户和密码后才能访问:

[[email protected] conf]# vim httpd.conf    #修改配置文件,基于组用户认证

[[email protected] conf]# vim htgroup   #建立组用户文件,内容如下:

myusers: hadoop john     #hadoop为htpasswd中存在的用户,john为htpasswd中不存在的用户,这                   里tom用户没在myusers组用户中

实验结果得知,只有hadoop用户能正常访问,john和tom用户无法访问。

是否启用用户家目录网页设置:

[[email protected] conf]# useradd hadoop  #新建hadoop用户

[[email protected] conf]# su - hadoop     #切换至hadoop用户

[[email protected] ~]$ mkdir public_html   #新建public_html目录

[[email protected] ~]$ cd public_html/

[[email protected] public_html]$ vim index.html  #建立索引网页

haha hadoop publichtml

[[email protected] public_html]$ cd

[[email protected] ~]$ chmod o+x /home/hadoop #更改hadoop家目录权限,是其他人可以进入目录

[[email protected] conf]# ll /home

总计 40

drwx------ 4 donggen donggen  4096 12-29 09:52 donggen

drwx-----x 5 hadoop  hadoop   4096 01-13 08:48 hadoop  #其他人增加进入目录的权限,否则无                                        法访问里面的网页

drwx------ 4 john    john     4096 12-29 08:13 john

drwx------ 2 root    root    16384 12-07 00:53 lost+found

[[email protected] conf]# service httpd restart

service httpd restart

停止 httpd:                                               [确定]

启动 httpd:                                               [确定]

[[email protected] conf]# httpd -t

Syntax OK

DirectoryIndex index.html index.html.var #默认打开的第一个网页为index.html,依次类推,第一                             个打不开,会自动搜索下一个默认网页。

Alias /icons/ "/var/www/icons/" # 路径别名

Alias /luntan "/bbs/forum"      #表示访问http://10.109.134.249/luntan网页就是访                              问/bbs/forum下的index.html网页

MPM:Multi Path Modules,它提供了可以选择的多处理模块(MPM),用来绑定到网络端口上,接受请求, 以及调度子进程处理请求。

mpm_winnt:windows响应请求的工作模型

prefork:一个请求用一个进程响应;(默认使用的处理请求的模型)

worker:一个请求用一个线程响应,(启动多个进程,每个进程生成多个线程)

event:一个进程处理多个请求

Apache(httpd)支持多种方式的虚拟主机配置:

一、定义
    所谓虚拟主机是指在一台服务器里运行几个网站,提供WEB、FTP、Mail等服务。

二、虚拟主机的实现方法有三种:

基于IP的方法,基于主机名的方法和基于端口的法官法。
    ①基于IP的方法:
  在服务器里绑定多个IP,然后配置WEB服务器,把多个网站绑定在不同的IP上。访问不同的IP,就看到不同的网站。
    ②基于端口的方法:
    一个IP地址,通过不同的端口实在不同网站的访问。
    ③基于主机名的方法:
    设置多个域名的A记录,使它们解析到同一个IP地址上,即同一个服务器上。然后,在服务器上配置WEB服务端,添加多个网站,为每个网站设定一个主机名。因为HTTP协议访问请求里包含有主机名信息,当WEB服务器收到访问请求时,就可以根据不同的主机名来访问不同的网站。

三、虚拟主机实现的基本配置

①基于IP虚拟主机的实现:
    多个ip,需要把中心主机取消
    打开web服务的主配置文档:vim /etc/httpd/conf/httpd.conf
    DocumentRoot 注释掉
    配置虚拟主机:
    <VirtualHost 192.168.0.20:80>
    DocumentRoot "/www/a.com"
    ServerName  www.a.com
    </VirtualHost>
    <VirtualHost 192.168.0.25:80>
    DocumentRoot "/www/b.com"
    ServerName  www.b.com
    </VirtualHost>
    vim /etc/hosts
    192.168.0.20  www.a.com
    192.168.0.25 www.b.com
    浏览器中输入IP地址进行实验效果的验证。
    ②基于端口:
    <VirtualHost 192.168.0.20:80>
    DocumentRoot "/www/a.com"
    ServerName  www.a.com
    </VirtualHost>
    <VirtualHost 192.168.0.20:8080>
    DocumentRoot "/www/b.com"
    ServerName  www.b.com
    </VirtualHost>
    ③基于主机名:
    开启:NameVirtualHost 192.168.0.20:80
    <VirtualHost *:80>
    ServerAdmin    www.a.com
    DocumentRoot /etc/httpd/aaa/a.com
    ServerName dummy-host.example.com
    ErrorLog logs/dummy-host.example.com-error_log
    CustomLog logs/dummy-host.example.com-access_log common
    </VirtualHost>
    <VirtualHost *:80>
    ServerAdmin    www.b.com
    DocumentRoot /etc/httpd/aaa/b.com
    </VirtualHost>

四、案例综合实现
    建立http服务器,要求:
    1)提供两个基于名称的虚拟主机:
    (a)www1.ilinux.org,页面文件目录为/var/www/html/www1;错误日志 为/var/log/httpd/www1.err,访问      日志为/var/log/httpd/www1.access;
    (b)www2.ilinux.org,页面文件目录为/var/www/html/www2;错误日志为/var/log/httpd/www2.err,访问日      志为/var/log/httpd/www2.access;
    (c)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名;
    2)www1主机仅允许192.168.0.0/24网络中的客户机访问;www2主机可以被所有主机访问;
     为http服务提供第3个虚拟主机,要求:
    1)www3.ilinux.org,页面文件目录为/var/www/html/www3;错误日志为/var/log/httpd/www3.err,访问日志      为/var/log/httpd/www3.access;
    2)为此虚拟主机提供基本认证功能,并为其提供两个虚拟用户webuser1和webuser2,
    密码均为redhat,要求允许此两用户在提供密码的情况下访问此站点;
    配置过程如下:
    ①安装web服务:yum -y install httpd
    ②进入主配置文档vim /etc/httpd/conf/httpd.conf
    <VirtualHost *:80>
    DocumentRoot "/var/www/html/www1"
    ServerName  www1.ilinux.org
    Errorlog /var/log/httpd/www1.err
    CustomLog /var/log/httpd/www1.access common
    <Directory "/var/www/html/www1">
    Options Indexes
    AllowOverride None
    Order allow,deny
    Allow from 192.168.0.0/24
    </Directory>
    </VirtualHost>
    <VirtualHost *:80>
    DocumentRoot "/var/www/html/www2"
    ServerName  www2.ilinux.org
    Errorlog /var/log/httpd/www2.err
    CustomLog /var/log/httpd/www2.access common
    <Directory "/var/www/html/www2">
    Options Indexes
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
    <VirtualHost *:80>
    DocumentRoot /var/www/html/www3
    ServerName www3.ilinux.org
    ErrorLog /var/log/httpd/www3.err
    CustomLog /var/log/httpd/www3.access combined
    <Directory "/var/www/html/www3">
    Options Indexes
    AllowOverride AuthConfig
    AuthName "AuthConfig"
    AuthType basic
    AuthUserFile /etc/httpd/.htpasswd
    require user webuser1 webuser2
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
    htpasswd -cm /etc/httpd/.htpasswd webuser1
    htpasswd -m /etc/httpd/.htpasswd webuser2
    ③分别在/var/www/html目录下创建www1,www2,www3目录
    vim /var/www/html/www1/index.html
    This is www1 test!
    vim /var/www/html/www2/index.html
    This is www2 test!
    vim /var/www/html/www3/index.html
    This is www3 test!
    ④service httpd start 启动web服务
    ⑤进行实验效果的验证:浏览器中分别输入www1.ilinux.org  www2.ilinux.org www3.ilinux.org

时间: 2024-07-31 14:35:06

linux命令:httpd 安装配置 elinks htpasswd的相关文章

第四篇(1):企业常用Linux web环境安装配置(apache、php、mysql)

上篇我们讲了基本的软件包管理和文件操作什么的,现在也要动手安装点有用的东西了吧! 本篇我会写出一个用yum安装apache.php.mysql的方法,最后再运行phpMyAdmin来管理数据库. 1.如何在Linux主机上安装apache 由于之前我们安装了完成的centos系统,所以可能系统有可能已经安装好了apache,所以我们先检查下是不是真的安装过了 先敲命令吧,yum list installed httpd* ,如果看到httpd已经安装,那么就yum -y remove httpd

So Easy! Oracle在Linux上的安装配置系列一

So Easy! Oracle在Linux上的安装配置系列一 本文为So Easy!Oracle在linux上的安装和配置序列的第一篇Oracle安装基础环境的搭建 VMware Workstation 11.0 配置和CentOS-6.6-x86_64安装 本文环境及所需软件: Win7 Sevice Pack1 内存 6GB VMware Workstation 11.0  build-2305329 CentOS-6.6-x86_64-bin-DVD1.iso Xmanger Enterp

VMware Linux 下 Nginx 安装配置 - nginx.conf 配置 [负载两个 Tomcat] (三)

首先启动Nginx 1. 转到 nginx 目录: /usr/local/nginx; 启动 nginx: /usr/local/nginx/nginx ubuntu 前要加 sudo; 关健配置 http 配置块下,一般设置在 zgip on 下: upstream localhost { #绿色对应 #ip_hash; server localhost:8090; server localhost:8080; } server / { location / { proxy_connect_t

So Easy! Oracle在Linux上的安装配置系列四

So Easy! Oracle在Linux上的安装配置系列四  监听器的配置 在创建了数库和各种数据库对象并装载了数据后,下一步是在数据库服务器与使用它的用户之间建立连 接,Oracle Net Services使这种连接成为可能.Oracle Net Services组件必须"存活"在客户机和服务器上,它们一般使用TCP/IP网络协议来建立客户机和数据库服务器之间的网络连接. 本文官方文档位置: http://docs.oracle.com/cd/E11882_01/network.

Linux下git安装配置

一.Linux下git安装配置 2013-07-28 20:32:10|  分类: 默认分类 |  标签:linux  git  server  |举报|字号 订阅 http://abomby.i.sohu.com/blog/view/168755260.htm http://www.linuxidc.com/Linux/2011-12/48555.htm Git是分布式的版本控制系统,实际上是不需要固定的服务器的,Git与svn的最大区别是,它的使用流程不需要联机,可以先将对代码的修改,评论,

Linux之tomcat 安装&配置&优化

Tomcat简介: 1.Tomcat就是用来解析jsp程序的一个软件 .(jsp是一种编程语言,即JAVA) 2.Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta项目中的一个核心项目,由   Apache.Sun和其他一些公司及个人共同开发而成. 3.Tomcat是一个轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开   发和调试JSP程序的首选. Tomcat的安装分为两个步骤:安装JDK和安装Tomca

linux命令和网络配置图步骤

 rpm -ivh MySQL-client...... 安装MySQL客户端的命令,没写完整 1  ls 2  cd 3  ls 4  ls -l 5  vim 6  cd 7  ls -l 8  shutdowm 9  man 10  shutdown 11  shutdown -h 12  reboot 13  vim/etc/sysconfig/network 14  cd 15  vim/etc/sysconfig/network 16  vim /etc/sysconfig/ne

So Easy! Oracle在Linux上的安装配置系列三使用create database创建数据库

本文为So Easy! Oracle在Linux上的安装配置系列的第三篇,使用create database创建数据库,本序列第一篇介绍了学习实验环境的搭建包括:在win 7中使用VMware Workstation 创建虚拟机,安装CentOS-6.6-x86_64,网络配置 和使用xshell连接远程linux服务器,上传Oracle软件和使用操作系统安装光盘搭建本地yum源,第二篇专门说了Oracle11g R2在CentOS6.6上的安装,包括Oracle安装前的准备工作,并以图文详细介

So Easy! Oracle在Linux上的安装配置系列五

So Easy! Oracle在Linux上的安装配置系列五 本篇是监听器的配置的续篇,上一小节我们创建了一个监听器,创建了密码文,在监听和实例都启动的情况下,从远程windows即时客户端连接到了oracle服务器.本篇我将继续说监听器,还将完成相关的实验 以下内容整理自网络 Oracle 监听器 Listener 是一个重要的数据库服务器组件,在整个 Oracle 体系结构中,扮演着重要的作用.它负责管理 Oracle 数据库和客户端之间的通讯,它在一个特定的网卡端口(默认是TCP 1521