linux 基础服务(二)

爱⌒轻易说出口 提交于 2021-01-01 06:35:15

登陆xshell的时候碰到个问题,突然不能登陆了如下图
linux  基础服务(二)
1.检查虚拟机的虚拟网络编辑器,改成如下配置,这里的名字是你的网络连接相同的,找一个能上网的连接,不要使用自动。
linux  基础服务(二)


httpd
基于端口的创建

[root@localhost conf.d]# rpm -ql httpd
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/httpd/logs
/etc/httpd/modules
/etc/httpd/run
/etc/logrotate.d/httpd
/etc/rc.d/init.d/htcacheclean
/etc/rc.d/init.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd
/usr/lib64/httpd
[root@localhost conf.d]# vim /etc/httpd/conf/httpd.conf
Listen 8080  (添加监听端口)
[root@localhost conf.d]# pwd
/etc/httpd/conf.d
[root@localhost conf.d]# vim test.conf 
 <VirtualHost *:8080>
     ServerAdmin 888.com  (这里可有可无,类似标签)
     DocumentRoot /var/www/test  (这里必须有,此文件的路径)
     ServerName www.888.com   (自定义域名)
     ErrorLog logs/www.888.com-error_log 
     CustomLog logs/www.888.com-access_log common
 </VirtualHost>
此内容在6系统里有模板: /etc/httpd/conf/httpd.conf(最后面能看到)
~                             
[root@localhost conf.d]# mkdir /var/www/test
[root@localhost conf.d]# echo 888 > /var/www/test/index.html
[root@localhost conf.d]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

windows这里:
linux  基础服务(二) (要在host文件里添加解析)

linux  基础服务(二)


**基于名称**

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
# Use name-based virtual hosting.
#

#NameVirtualHost *:80 (把前面的注释去掉,6系统是这样,7默认打开)

[root@localhost conf.d]# cp -p test.conf baidu.conf
[root@localhost conf.d]# cp -p test.conf taobao.conf
[root@localhost conf.d]# vim baidu.conf
[root@localhost conf.d]# vim baidu.conf
[root@localhost conf.d]# mkdir /var/www/baidu.com
[root@localhost conf.d]# echo "wo shi bai du " > /var/www/baidu.com/index.html (默认识别index.html)
[root@localhost conf.d]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [Tue May 01 22:35:52 2018] [warn] default VirtualHost overlap on port 8080, the first has precedence
[ OK ]
*(使用windows测试,和基于端口的添加方式一样)










**http针对目录做限制**

[root@localhost conf.d]# cat taobao.conf
<VirtualHost *:80>
DocumentRoot /var/www/taobao.com
ServerName www.taobao.com
ErrorLog logs/www.888.com-error_log
CustomLog logs/www.888.com-access_log common
</VirtualHost>





alias /boke1 "/var/www/baicu.com/" (就是你点开boke1,就会跳转到后面指定的地方,这里是/baidu.com/,/不能少)
<Directory "/var/www/taobao.com"> (针对目录做限制)
Options -Indexes (这里可以写好多控制语句,这里就不赘述了)
</Directory>


[root@localhost conf.d]# vim welcome.conf
<LocationMatch "^/+$">
Options -Indexes (前面-代表不显示主页) (这里我先去掉-)
ErrorDocument 403 /error/noindex.html
</LocationMatch>



links www.taobao.com (如下图)

linux  基础服务(二)


**网站认证**

[root@localhost conf.d]# vim taobao.conf
<VirtualHost *:80>
DocumentRoot /var/www/taobao.com
ServerName www.taobao.com
ErrorLog logs/www.888.com-error_log
CustomLog logs/www.888.com-access_log common
</VirtualHost>





<Directory "/var/www/taobao.com">
AllowOverride AuthConfig
AuthName "login"
AuthType basic
AuthUserFile "/etc/httpd/login"
Require valid-user
</Directory>





[root@localhost conf.d]# htpasswd -cmb /etc/httpd/login boke1 123 (创建用户和密码,第二次创建就不用加选项 c 了)
Adding password for user boke1
[root@localhost conf.d]# cat /etc/httpd/login
boke1:$apr1$H93q.SMI$F6.yYV2IgGyMzN4M4y.Tm.


测试时先关闭防火墙
*(这里注意下,6和7原理是一样的,就是有些写法不一样)



**防火墙**
https://blog.51cto.com/13559618/2062203  (这里写的不错)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!