1. 程式人生 > >linux-http服務搭建

linux-http服務搭建

一.安裝http
1.yum install http -y  systemctl start httpd     systemctl enable httpd              
2.改變預設檔案DirectoryIndex  westos  預設檔案改成westos
3.改變預設目錄
119 #DocumentRoot "/var/www/html"
120 DocumentRoot "/westos/html/"
121 <Directory "/westos/html">
122             Require all granted
123 </Directory>
需要注意的是如果selinux是開著的需要給檔案加標籤,如下
semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'
restorecon -RvvF /westos/  重新整理
這樣就改變成功
二.設定使用者許可權
1.編輯主配置檔案/etc/httpd/conf/httpd.conf
配置結果如下
Require all granted 允許所有人登陸訪問  
Order Deny,Allow 寫在後面的級別高
ALLow from 172.25.254.22允許來自22的使用者登陸
2.設定使用者密碼登陸
建立加密使用者和密碼
這個需要在/etc/httpd/conf路徑下進行配置配置如下
htpasswd -cm authfile admin 需要注意的是在建立第二個使用者時要去掉c不然新建立的使用者會覆蓋掉原來的使用者

配置主配置檔案/etc/httpd/conf/httpd.conf配置結果如下圖


三.在本機上配置http服務
1.建立訪問目錄/var/www/news.westos.com/ -p
2.編輯/var/www/news.westos.com/westos內容隨便寫

3.cd到etc/httpd/conf.d/下配置default.conf和news.conf配置