鸟哥私房菜实践(11)- WWW
来源:互联网 发布:js 实参 形参 编辑:程序博客网 时间:2024/06/06 08:27
LAMP (Linux + Apache + MySQL + PHP)
1、安装软件
yum install httpd.x86_64 php.x86_64 mysql.x86_64 mysql-server.x86_64 php-mysql.x86_64
2、简单修改配置文件,/etc/httpd/conf/httpd.conf
KeepAlive On
# AddDefaultCharset UTF-8
3、配置文件语法检查,service httpd configtest
4、启动服务,service httpd start
5、编写测试文件
vim /var/www/html/phpinfo.php
<?php phpinfo (); ?>
6、使用文字浏览器测试
links --dump http://127.0.0.1/phpinfo.php
7、修改mysql数据库的root口令
/usr/bin/mysqladmin -u root password '123456'
8、创建测试数据库与用户
mysql -u root -p
create database tdb;
grant all privileges on tdb.* to uu@localhost identified by 'uu' ;
============== Apache 服务器的进阶设定 =============
一、启动用户的个人网站 (权限是重点)
1). 编辑配置文件,/etc/httpd/conf/httpd.conf
<IfModule mod_userdir.c>
#UserDir disable
UserDir www
</IfModule>
2). 使用个人用户登录,比如zz
mkdir www
chmod g+x,o+x /home/zz
echo "Test your home" >> www/index.html
3). 测试,links --dump http://127.0.0.1/~zz
二、启动某个目录的 CGI (perl) 程序执行权限
1). 安装软件,yum install mod_perl.x86_64
2). 编辑配置文件,/etc/httpd/conf/httpd.conf
AddHandler cgi-script .cgi .pl
3). 编写网页脚本
vim /var/www/cgi-bin/helloworld.pl
#!/usr/bin/perl
print "Content-type: text/html\r\n\r\n";
print "Hello, World.";
4). 添加执行权限,chmod +x /var/www/cgi-bin/helloworld.pl
5). 测试,links --dump http://127.0.0.1/cgi-bin/helloworld.pl
三、浏览权限的设定动作 (order, limit)
1). 关键字Order限制客户端来源
Order deny,allow:以 deny 优先处理,但没有写入规则的则默认为 allow。
Order allow,deny:以 allow 为优先处理,但没有写入规则的则默认为 deny
鸟哥写的有点复杂了,不要同时指定allow与deny
Order deny,allow --此时只指定deny即可,其他的都允许
Order allow,deny --此时只指定allow即可,其他的都禁止
比如:
Order allow,deny
Allow from 192.168.122.1
最终效果:只允许192.168.122.1访问
比如:
Order deny,allow
Deny from 127.0.0.1
最终效果:只禁止本机访问
2). 关键字limit限制客户端能进行的动作,示例:
# 先允许能够进行 GET, POST 与 OPTIONS 啦!
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
# 再规定除了这三个动作之外,其他的动作通通不允许啦!
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
四、服务器状态说明网页
1). vim /etc/httpd/conf/httpd.conf
# 先确认下面这行存在
LoadModule status_module modules/mod_status.so
修改下面两段定义
ExtendedStatus On
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
2). 验证,links --dump http://127.0.0.1/server-status
五、.htaccess 与认证网页设定
1). 建立保护目录的数据
mkdir /var/www/html/protect
vim /var/www/html/protect/index.html
<html>
<head><title>password protect test</title></head>
<body>welcome.</body>
</html>
2). 以 root 的身份处理 httpd.conf 的设定数据
确认存在
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>
# 在某个不受影响的地方加入这一段:
<Directory "/var/www/html/protect">
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
3). 重启服务,service httpd restart
4). 建立保护目录下的 .htaccess 档案 (只要有权限即可执行)
vim /var/www/html/protect/.htaccess
AuthName "Protect test by .htaccess"
Authtype Basic
AuthUserFile /var/www/apache.passwd
require user test
限制只有test用户可以访问
5). 建立密码档案 htpasswd (只要有权限即可执行)
htpasswd -c /var/www/apache.passwd test
htpasswd /var/www/apache.passwd test1
cat /var/www/apache.passwd
备注:只有首次执行需要使用-c选项,否则文件内容会被清空
6). 验证,links --dump http://127.0.0.1/protect
六、虚拟主机的设定 (重要!)
所谓的虚拟主机,基本上就是『让你的一部服务器上面,有好多个 "主网页" 存在,也就是说,硬件实际上只有一部主机,但是由网站网址上来看,则似乎有多部主机存在的样子!』
架设的大前提:同一个 IP 有多个主机名啦!
1). 规划
主机名 对应的主目录
www.c65 /var/www/html
ftp.c65 /var/ftp
2). 先建立所需要的目录及主页文件
yum install vsftpd.x86_64
echo "ftp.test" > /var/ftp/index.html
3). 编辑配置文件,用额外的档案来设定
vim /etc/httpd/conf.d/virt.conf
NameVirtualHost *:80
<Directory "/var/ftp">
Options FollowSymLinks Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName www.c65
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName ftp.c65
DocumentRoot /var/ftp
</VirtualHost>
4). 重启服务,service httpd restart
5). 编辑/etc/hosts,添加规划的主机名称
127.0.0.1 www.c65
127.0.0.1 ftp.c65
6). 验证
links --dump http://www.c65
links --dump http://ftp.c65
七、建立联机加密网站 (https)
1). 安装软件,yum install mod_ssl.x86_64
2). 重启服务,service httpd restart
3). 修改links命令的配置文件,不再检查证书
vi /etc/elinks.conf
set connection.ssl.cert_verify = 0
4). 验证,links --dump https://127.0.0.1
八、拥有自制凭证的 https
1、生成证书(需要先建立一把 private key 用以给 SSL 证书签字)
1). 生成私钥
cd /etc/pki/tls/certs
make zcg0.key
输入两次密码
2). 删除私钥中的密码
mv zcg0.key zcg0.key.raw
openssl rsa -in zcg0.key.raw -out zcg0.key
chmod 400 zcg0.key
rm zcg0.key.raw
3). 生成证书(如果需要修改证书的期限,则修改Makefile中的数字)
make zcg0.crt SERIAL=2014112801
过程中需要输入一些区域信息
2、修改 ssl.conf 的内容,使用自制凭证
vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/pki/tls/certs/zcg0.crt
SSLCertificateKeyFile /etc/pki/tls/certs/zcg0.key
3、重启服务,service httpd restart
4、验证,不知道如何通过links命令查看证书内容,借助于图形浏览器来查看吧
九、将加密首页与非加密首页分离
1、生成目录与默认的首页文件 index.html
mkdir /var/www/https
echo "This is https' home" > /var/www/https/index.html
2、修改ssl.conf配置文件
vim /etc/httpd/conf.d/ssl.conf
DocumentRoot "/var/www/https"
ServerName *:443
3、重启服务,service httpd restart
4、验证,对比两者的差异
links --dump https://127.0.0.1
links --dump http://127.0.0.1
1、安装软件
yum install httpd.x86_64 php.x86_64 mysql.x86_64 mysql-server.x86_64 php-mysql.x86_64
2、简单修改配置文件,/etc/httpd/conf/httpd.conf
KeepAlive On
# AddDefaultCharset UTF-8
3、配置文件语法检查,service httpd configtest
4、启动服务,service httpd start
5、编写测试文件
vim /var/www/html/phpinfo.php
<?php phpinfo (); ?>
6、使用文字浏览器测试
links --dump http://127.0.0.1/phpinfo.php
7、修改mysql数据库的root口令
/usr/bin/mysqladmin -u root password '123456'
8、创建测试数据库与用户
mysql -u root -p
create database tdb;
grant all privileges on tdb.* to uu@localhost identified by 'uu' ;
============== Apache 服务器的进阶设定 =============
一、启动用户的个人网站 (权限是重点)
1). 编辑配置文件,/etc/httpd/conf/httpd.conf
<IfModule mod_userdir.c>
#UserDir disable
UserDir www
</IfModule>
2). 使用个人用户登录,比如zz
mkdir www
chmod g+x,o+x /home/zz
echo "Test your home" >> www/index.html
3). 测试,links --dump http://127.0.0.1/~zz
二、启动某个目录的 CGI (perl) 程序执行权限
1). 安装软件,yum install mod_perl.x86_64
2). 编辑配置文件,/etc/httpd/conf/httpd.conf
AddHandler cgi-script .cgi .pl
3). 编写网页脚本
vim /var/www/cgi-bin/helloworld.pl
#!/usr/bin/perl
print "Content-type: text/html\r\n\r\n";
print "Hello, World.";
4). 添加执行权限,chmod +x /var/www/cgi-bin/helloworld.pl
5). 测试,links --dump http://127.0.0.1/cgi-bin/helloworld.pl
三、浏览权限的设定动作 (order, limit)
1). 关键字Order限制客户端来源
Order deny,allow:以 deny 优先处理,但没有写入规则的则默认为 allow。
Order allow,deny:以 allow 为优先处理,但没有写入规则的则默认为 deny
鸟哥写的有点复杂了,不要同时指定allow与deny
Order deny,allow --此时只指定deny即可,其他的都允许
Order allow,deny --此时只指定allow即可,其他的都禁止
比如:
Order allow,deny
Allow from 192.168.122.1
最终效果:只允许192.168.122.1访问
比如:
Order deny,allow
Deny from 127.0.0.1
最终效果:只禁止本机访问
2). 关键字limit限制客户端能进行的动作,示例:
# 先允许能够进行 GET, POST 与 OPTIONS 啦!
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
# 再规定除了这三个动作之外,其他的动作通通不允许啦!
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
四、服务器状态说明网页
1). vim /etc/httpd/conf/httpd.conf
# 先确认下面这行存在
LoadModule status_module modules/mod_status.so
修改下面两段定义
ExtendedStatus On
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
2). 验证,links --dump http://127.0.0.1/server-status
五、.htaccess 与认证网页设定
1). 建立保护目录的数据
mkdir /var/www/html/protect
vim /var/www/html/protect/index.html
<html>
<head><title>password protect test</title></head>
<body>welcome.</body>
</html>
2). 以 root 的身份处理 httpd.conf 的设定数据
确认存在
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>
# 在某个不受影响的地方加入这一段:
<Directory "/var/www/html/protect">
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
3). 重启服务,service httpd restart
4). 建立保护目录下的 .htaccess 档案 (只要有权限即可执行)
vim /var/www/html/protect/.htaccess
AuthName "Protect test by .htaccess"
Authtype Basic
AuthUserFile /var/www/apache.passwd
require user test
限制只有test用户可以访问
5). 建立密码档案 htpasswd (只要有权限即可执行)
htpasswd -c /var/www/apache.passwd test
htpasswd /var/www/apache.passwd test1
cat /var/www/apache.passwd
备注:只有首次执行需要使用-c选项,否则文件内容会被清空
6). 验证,links --dump http://127.0.0.1/protect
六、虚拟主机的设定 (重要!)
所谓的虚拟主机,基本上就是『让你的一部服务器上面,有好多个 "主网页" 存在,也就是说,硬件实际上只有一部主机,但是由网站网址上来看,则似乎有多部主机存在的样子!』
架设的大前提:同一个 IP 有多个主机名啦!
1). 规划
主机名 对应的主目录
www.c65 /var/www/html
ftp.c65 /var/ftp
2). 先建立所需要的目录及主页文件
yum install vsftpd.x86_64
echo "ftp.test" > /var/ftp/index.html
3). 编辑配置文件,用额外的档案来设定
vim /etc/httpd/conf.d/virt.conf
NameVirtualHost *:80
<Directory "/var/ftp">
Options FollowSymLinks Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName www.c65
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName ftp.c65
DocumentRoot /var/ftp
</VirtualHost>
4). 重启服务,service httpd restart
5). 编辑/etc/hosts,添加规划的主机名称
127.0.0.1 www.c65
127.0.0.1 ftp.c65
6). 验证
links --dump http://www.c65
links --dump http://ftp.c65
七、建立联机加密网站 (https)
1). 安装软件,yum install mod_ssl.x86_64
2). 重启服务,service httpd restart
3). 修改links命令的配置文件,不再检查证书
vi /etc/elinks.conf
set connection.ssl.cert_verify = 0
4). 验证,links --dump https://127.0.0.1
八、拥有自制凭证的 https
1、生成证书(需要先建立一把 private key 用以给 SSL 证书签字)
1). 生成私钥
cd /etc/pki/tls/certs
make zcg0.key
输入两次密码
2). 删除私钥中的密码
mv zcg0.key zcg0.key.raw
openssl rsa -in zcg0.key.raw -out zcg0.key
chmod 400 zcg0.key
rm zcg0.key.raw
3). 生成证书(如果需要修改证书的期限,则修改Makefile中的数字)
make zcg0.crt SERIAL=2014112801
过程中需要输入一些区域信息
2、修改 ssl.conf 的内容,使用自制凭证
vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/pki/tls/certs/zcg0.crt
SSLCertificateKeyFile /etc/pki/tls/certs/zcg0.key
3、重启服务,service httpd restart
4、验证,不知道如何通过links命令查看证书内容,借助于图形浏览器来查看吧
九、将加密首页与非加密首页分离
1、生成目录与默认的首页文件 index.html
mkdir /var/www/https
echo "This is https' home" > /var/www/https/index.html
2、修改ssl.conf配置文件
vim /etc/httpd/conf.d/ssl.conf
DocumentRoot "/var/www/https"
ServerName *:443
3、重启服务,service httpd restart
4、验证,对比两者的差异
links --dump https://127.0.0.1
links --dump http://127.0.0.1
0 0
- 鸟哥私房菜实践(11)- WWW
- 鸟哥私房菜实践(1)- ACL
- 鸟哥私房菜实践(2)- quota
- 鸟哥私房菜实践(3)- RAID
- 鸟哥私房菜实践(4)- LVM
- 鸟哥私房菜实践(5)- SELinux
- 鸟哥私房菜实践(6)- NFS
- 鸟哥私房菜实践(7)- NIS
- 鸟哥私房菜实践(8)- SAMBA
- 鸟哥私房菜实践(9)- SAMBA PDC
- 鸟哥私房菜实践(10)- ISCSI
- 鸟哥私房菜实践(12)- FTP
- 鸟哥私房菜实践(13)- DNS
- 鸟哥私房菜实践(14)- PROXY
- 鸟哥私房菜实践(15)- postfix
- 鸟哥的linux私房菜之WWW服务器--摘录
- 鸟哥的Linux私房菜(服务器)- 第二十章、WWW 伺服器
- 鸟哥私房菜
- intent调用代码总结
- ciso 2811 或2600 work as console server configure 配置
- 神经网络编程入门
- 如何在网页中嵌入自己想要的字体(实例下载)
- web服务器脚本安全 基础学习 总结【对应php 脚本】
- 鸟哥私房菜实践(11)- WWW
- UITableView划动删除的实现
- UML序列图总结
- javaScript call 函数的用法说明
- 剑指offer系列源码-二叉树中和为某一值的路径
- Android ExpandableListView Demo
- 视频通讯应用的音频和视频技术
- 树、森林与二叉树的转换
- nginx php-fpm调优