设为首页 收藏本站
查看: 2001|回复: 0

[经验分享] WEB服务器之apache

[复制链接]

尚未签到

发表于 2018-11-23 07:14:08 | 显示全部楼层 |阅读模式
  安装配置
软件包:httpd
服务端口:80/tcp(http) 443/tcp(https, http + ssl)
配置文件:/etc/httpd/conf/httpd.conf
        /etc/httpd/conf.d/*.conf
/etc/httpd/conf.d/welcome.conf//默认测试页面,建议删除
[root@node1 ~]# yum -y install httpd
[root@node1 ~]# tree /etc/httpd/
/etc/httpd/
|-- conf
|   |-- httpd.conf

|   `-- magic
|-- conf.d
|   |-- README
|   |-- proxy_ajp.conf
|   `-- welcome.conf
|-- logs -> ../../var/log/httpd
|-- modules -> ../../usr/lib/httpd/modules
`-- run -> ../../var/run

[root@node1 ~]# vim /etc/httpd/conf/httpd.conf
### Section 1: Global Environment

ServerRoot "/etc/httpd"//Apache安装目录
PidFile run/httpd.pid//pid文件
Listen 80//监听的端口
# Dynamic Shared Object (DSO) Support  //  /etc/httpd/modules/
LoadModule auth_basic_module modules/mod_auth_basic.so
Include conf.d/*.conf//包含/etc/httpd/conf.d/*.conf
User apache//运行Apache的用户
Group apache//运行Apache的组
### Section 2: 'Main' server configuration
ServerAdmin root@localhost

#ServerName www.example.com:80
DocumentRoot "/var/www/html"//站点主目录
DirectoryIndex index.html index.php //设置网站首页
### Section 3: Virtual Hosts

  Apache配置示例 DSC0000.jpg
  

  

  

  Apache配置示例
  [root@node1 html]# pwd
/var/www/html

  [root@node1 html]# cat index.html
welcome to zhangyunming

  [root@node1 html]# service httpd start
启动 httpd:                                               [确定]

  

  [root@node1 html]# chkconfig httpd on
[root@node1 html]# ps auxf | grep httpd |grep -v 'grep'

root     32731  0.0  1.1  10092  2912 ?        Ss   13:12   0:00 /usr/sbin/httpd
apache   32732  0.0  0.8  10092  2056 ?        S    13:12   0:00  \_ /usr/sbin/httpd
apache   32733  0.0  0.8  10092  2056 ?        S    13:12   0:00  \_ /usr/sbin/httpd
apache   32734  0.0  0.8  10092  2056 ?        S    13:12   0:00  \_ /usr/sbin/httpd
apache   32735  0.0  0.8  10092  2056 ?        S    13:12   0:00  \_ /usr/sbin/httpd
apache   32736  0.0  0.8  10092  2056 ?        S    13:12   0:00  \_ /usr/sbin/httpd

apache   32737  0.0  0.8  10092  2056 ?        S    13:12   0:00  \_ /usr/sbin/httpd
apache   32738  0.0  0.8  10092  2056 ?        S    13:12   0:00  \_ /usr/sbin/httpd
apache   32739  0.0  0.8  10092  2056 ?        S    13:12   0:00  \_ /usr/sbin/httpd

[root@node1 html]# netstat -tnlp |grep :80
tcp        0      0 0.0.0.0:80          0.0.0.0:*      LISTEN      32731/httpd  

[root@node1 html]# netstat -an |grep :80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      
tcp        0      0 192.168.0.2:80              192.168.0.40:55410          TIME_WAIT   
tcp        0      0 192.168.0.2:80              192.168.0.40:55411          TIME_WAIT   
tcp        0      0 192.168.0.2:80              192.168.0.40:55412          TIME_WAIT   
tcp        0      0 192.168.0.2:80              192.168.0.195:1038          TIME_WAIT   

[root@node1 ~]# elinks -dump 192.168.0.2
   welcome to zhangyunming.

   DSC0001.jpg
  

  基于用户家目录发布网
UserDir public_html


service httpd restart

useradd yun
useradd ming

mkdir /home/yun/public_html
mkdir /home/ming/public_html


chmod 755 /home/yun /home/ming

echo "This is yun's home" >> /home/yun/public_html/index.html
echo "This is ming's home" >> /home/ming/public_html/index.html

firefox 浏览器测试
http://192.168.0.1/~robin
http://192.168.0.1/~zorro
[root@node1 ~]# elinks --dump http://localhost/~yun   文本测试方法:
   This is yun's homepage
[root@node1 ~]# elinks --dump http://localhost/~ming
   This is ming's homepage

DSC0002.jpg

  别名方式发布
Alias
/aaa "/home/yun/public_html"


    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all


Alias
/bbb "/home/ming/public_html"


    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all

   DSC0003.jpg
  本机测试
[root@node1 html]# elinks --dump http://localhost/aaa
   This is yun's homepage

[root@node1 html]# elinks --dump http://localhost/bbb
   This is ming's homepage

   DSC0004.jpg
  

  

  基于用户验证的访问控制
[root@node1 ~]# vim /home/robin/public_html/.htaccess

authname "hello,welcom to my homepage"
authtype basic
authuserfile "/home/robin/public_html/.htpasswd"
require valid-user
~                 
[root@node1 ~]# htpasswd -c /home/robin/public_html/.htpasswd wang
New password: 123456
Re-type new password:123456
Adding password for user wang
[root@station51 ~]# /etc/init.d/httpd restart
停止 httpd:                                               [确定]
启动 httpd:                                               [确定]

用firefox 测试: http://192.168.1.116/aaa                     输入用户名aaa 密码:123456
  

  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-638389-1-1.html 上篇帖子: Linux下源码安装Apache+SVN服务器 下篇帖子: apache与php(FastCGI)安装配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表