配置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
增加这些文件: