配置httpd web服務:
1、rpm -ql httpd|less 查看配置文件。 /etc/httpd/conf/httpd.conf
2、頁面的主目錄/var/www/index.html
3、 service httpd restart啟動服務centos6,systemctl restart httpd.service centos6.
4、語法檢查:service httpd configtest http-t
5、 ps aux進程運行情況檢查
6、ab -c 20 -n 1000 http://ip地址/創建多少個並發的線程等。
7、不暴露服務版本的命令:隱藏版本信息:vim /etc/httpd/conf/httpd.conf 文件中插入此信息Server Tokens Prod
8、配置文件里面修改ip和監聽端口。
9、判斷連接方式,telnet 192.168.142.133 80 首先yum安裝Telnet。默認不是持久連接,秒內不連接就會自動斷開。/etc/httpd/conf/httpd.conf改變的話在配置文件里面改。
10、cd /var/www/html 頁面文件index.html存放位置,不設置默認為報錯頁面。
11、更改頁面存放的文件夾:首先制作新的頁面文件,
vim /etc/httpd/conf/httpd.conf 在httpd主配置文件的頁面中。把DocumentRoot "/var/www/html" 這行按照要求改成所在的文件夾下面就可以了。curl ip訪問就可以了。
語法檢查時候出現一行servername,在主配置文件中把servername那行按照要求設置。
12、網站訪問不指定文件名,默認訪問index.html文件,更改配置文件的話,會默認找到更改的文件。links連接,首先要yum 安裝links。
13、/etc/httpd/conf.d/ welcome.conf 更改此文件后,顯示沒有權限。
<Directory "/var/www/html"> options indexs在配置文件下更改此文件,用戶就可以訪問別的頁面。
14、創建軟連接:在/app/website 在利用ln -s /etc/fstab fstab 創建軟連接。配置文件中增加options indexs FollowSymlinks,允許軟連接。
15、控制主機能否訪問我的網站:order allow,deny 放在后面的優先級最高。配置文件中增加這些。allow ip地址 deny ip地址。
16、日志格式控制:
/var/log/httpd/ 在這個文件夾下,改的話就改配置文件。
17、頁面跳轉。在app/website文件下創建跳轉到的文件下。
18、可以定義文件別名,alias/path/.
19、登錄網站利用用戶名和口令登錄。Htpasswd -c /etc/httpd/conf.d/.httpuser user1(用戶) 網站的配置文件下。配置文件下創建require user 用戶名。還可以分組。
20、家目錄共享,mod_userdir.so。
21、不顯示版本信息,安全性。配置文件中加,serversignature on|off。也可以放置郵箱。
22、Server-status顯示詳細的信息等。
23、虛擬主機:
mkdir /app/website{1,2,3} 創建三個文件夾。
[root@localhost app]# echo /app/website1 > /app/website1/index.html
[root@localhost app]# echo /app/website2 > /app/website2/index.html
[root@localhost app]# echo /app/website3 > /app/website3/index.html 制作主頁文件。
[root@localhost website]# ip addr add 192.168.118.101/24 dev eth3
[root@localhost website]# ip addr add 192.168.118.102/24 dev eth3
[root@localhost website]# ip addr add 192.168.118.103/24 dev eth3 創建三個ip地址。S
[root@localhost website]# vim /etc/httpd/conf.d/vhosts.conf ip關聯網站。一一對應。
改配置文件麻煩,所以自己創建一個[root@localhost website]# vim /etc/httpd/conf.d/vhosts.conf 虛擬主機。
配置文件:<VirtualHost 192.168.118.101:80>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /app/website1/
ServerName www.a.com
ErrorLog logs/webste1-error_log
CustomLog logs/website1-access_log common
</VirtualHost>
<VirtualHost 192.168.118.102:80>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /app/website2/
ServerName www.b.com
# ServerName dummy-host.example.com
ErrorLog logs/webste2-error_log
CustomLog logs/website2-access_log common
</VirtualHost>
<VirtualHost 192.168.118.103:80>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /app/website3/
ServerName www.c.com
# ServerName dummy-host.example.com
ErrorLog logs/webste3-error_log
CustomLog logs/website3-access_log common
</VirtualHost>
通過端口號區分:首先默認恢復原來 的ip。
更改文件:
listen 81
listen 82
listen 83
<VirtualHost *:81>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /app/website1/
ServerName www.a.com
ErrorLog logs/webste1-error_log
CustomLog logs/website1-access_log common
</VirtualHost>
<VirtualHost *:82>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /app/website2/
ServerName www.b.com
# ServerName dummy-host.example.com
ErrorLog logs/webste2-error_log
CustomLog logs/website2-access_log common
</VirtualHost>
<VirtualHost *:83>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /app/website3/
ServerName www.c.com
# ServerName dummy-host.example.com
ErrorLog logs/webste3-error_log
CustomLog logs/website3-access_log common
</VirtualHost>
第三實現:
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.118.138 www.a1.com www.b1.com www.c1.com
增加這些文件: