linux 基礎服務(二)

語言: CN / TW / HK

登陸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  (這裡寫的不錯)