【WEB相关】

===============WEB服务================
静态网站:*.html *.htm

动态网站:*.php *.jsp *.cgi *.asp
PHP:
LAMP: Linux + Apache + Mysql + PHP/Perl/Python
LNMP(LEMP): Linux + Nginx + Mysql + PHP(FastCGI)

JSP:
Apache + Tomcat
LAMP + Tomcat
Nginx + Tomcat
IBM WebSphere

Web服务器软件:
Apache、Nginx、IIS、Tomcat、Lighttpd、IBM WebSphere

==================================================

Apache: www.apache.org
软件包:httpd
服务端口: 80/tcp(http) 443/tcp(https,http + ssl)
配置文件:/etc/httpd/conf/httpd.conf
        /etc/httpd/conf.d/*.conf
/etc/httpd/conf.d/welcome.conf     默认测试页面

/usr/local/apache2  //源码安装后配置目录


[root@station230 ~]# service httpd restart
[root@station230 ~]# rm -rf /etc/httpd/conf.d/welcome.conf

You may now add content to the directory /var/www/html/. Note that until you do so, people visiting your website will see this page, and not your content. To prevent this page from ever being used, follow the instructions in the file /etc/httpd/conf.d/welcome.conf.

[root@station230 ~]# cat /var/www/html/1.html
uplooking 01.
[root@station230 ~]# cat /var/www/html/index.html
index.html uplooking

配置Apache:
[root@station230 ~]# tree /etc/httpd/          安装目录
/etc/httpd/
|-- conf
|   |-- httpd.conf
|   `-- magic
|-- conf.d
|   |-- README
|   `-- proxy_ajp.conf
|-- logs -> ../../var/log/httpd
|-- modules -> ../../usr/lib/httpd/modules
`-- run -> ../../var/run

[root@station230 ~]# vim /etc/httpd/conf/httpd.conf
### Section 1: Global Environment
ServerRoot "/etc/httpd"          //Apache安装目录
PidFile run/httpd.pid          //进程文件
Listen 80               //监听端口
客户访问:http://192.168.2.115:81
LoadModule auth_basic_module modules/mod_auth_basic.so     //加载模块
Include conf.d/*.conf          //包含conf.d下的*.conf文件
User apache               //运行Apache的用户
Group apache               //运行Apache的用户组
ServerTokens Prod          //隐藏apache 版本号


两种运行模式:
[root@station230 ~]# httpd -l     //查看httpd进程当前使用的模式
Compiled in modules:
  core.c
  prefork.c          //当前为进程模式
  http_core.c
  mod_so.c
# prefork MPM          进程模式
<IfModule prefork.c>
StartServers       10     //初始建立的进程数(1个父进程,8个子进程)
MinSpareServers    10     //最小空闲的进程数
MaxSpareServers    15     //最大空闲的进程数
ServerLimit        2000     //服务器最大并发连接限制
MaxClients         1500     //服务器最大并发访问量    
MaxRequestsPerChild  4000 //每个子进程在其生命周期内允许响应的最大请求数,达到会结束,0永不
</IfModule>

# worker MPM          线程模式
<IfModule worker.c>
StartServers        2     //初始建立的进程数 <=====
MaxClients          2000 //最大的并发访问量(线程)
MinSpareThreads     100     //最小空闲的线程数
MaxSpareThreads     200     //最大空间的线程数
ThreadsPerChild     50     //每个进程建立的线程数<=====
MaxRequestsPerChild  0  //每个子进程在其生命周期内允许响应的最大请求数,达到会结束,0永不
</IfModule>

切换模式:
[root@station230 ~]# cd /usr/sbin
[root@station230 sbin]# ls httpd*
httpd  httpd.event  httpd.worker
[root@station230 sbin]#
[root@station230 sbin]# mv httpd httpd.prefork
[root@station230 sbin]# cp httpd.worker httpd
[root@station230 sbin]# service httpd restart
[root@station230 sbin]# httpd -l
Compiled in modules:
  core.c
  worker.c               //线程模式
  http_core.c
  mod_so.c
[root@station230 sbin]# ps aux |grep httpd
root      4326  0.0  0.1  10184  3144 ?        Ss   14:23   0:00 /usr/sbin/httpd
apache    4327  0.0  0.1 286820  2700 ?        Sl   14:23   0:00 /usr/sbin/httpd
apache    4329  0.0  0.1 286820  2704 ?        Sl   14:23   0:00 /usr/sbin/httpd
root      4387  0.0  0.0   4264   672 pts/1    R+   14:23   0:00 grep httpd
切回到进程模式....


### Section 2: 'Main' server configuration     主网站,默认网站
ServerAdmin root@localhost          //管理员mail
ServerName www.example.com          //网站名
DocumentRoot "/var/www/html"          //网站主目录
//以下设置/var/www/html访问权限
<Directory "/var/www/html">
    Options Indexes FollowSymLinks     //Indexes索引目录,(没有默认主页时)。FollowSymLinks支持符号链接
    AllowOverride None               //是否允许覆盖
    Order allow,deny              
    Allow from all
</Directory>
DirectoryIndex index.html index.html.var//设置默认主页
ErrorLog logs/error_log               //错误日志
CustomLog logs/access_log combined     //访问日志
Alias /icons/ "/var/www/icons/"          //别名。  icons 是/var/www/html目录下的(可以不存在)。 "/var/www/icons"是真实路径

AddDefaultCharset UTF-8               //字符集
=================================================
awstats      // apache日志分析软件

### Section 3: Virtual Hosts     实现多个站点
Apache虚拟主机功能:
基于IP:     每个网站一个IP               对客户访问是透明的  SSL
基于主机名:     所有网站仅用一个IP          对客户访问是透明的    
基于端口:     所有网站仅用一个IP,但端口不同     对客户访问是不透明的

===基于主机名(基于名称,基于主机头)name-based 一个IP对应多个主机名
规划:
网站               IP          主目录               log     ServerAdmin
www.tianyun.com          192.168.2.115     /webroot/tianyun
www.126.com          192.168.2.115     /webroot/126
www.uplooking.com     192.168.2.115     /webroot/uplooking

一、DNS解析
www.tianyun.com     tianyun.com ==>     192.168.2.115
www.126.com 126.com          ==>     192.168.2.115
www.uplooking.com  uplooking.com ==>     192.168.2.115

二、Apache虚拟主机
1. 准备工作
[root@station230 ~]# mkdir -p /webroot/{126,tianyun,uplooking}
[root@station230 ~]# echo "www.126.com" > /webroot/126/index.html
[root@station230 ~]# echo "www.tianyun.com" > /webroot/tianyun/index.html
[root@station230 ~]# echo "www.uplooking.com" > /webroot/uplooking/index.html
2.配置Apache实现虚拟主机
[root@station230 ~]# vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80     //支持基于名字的虚拟主机
<VirtualHost *:80>
    DocumentRoot /webroot/126
    ServerName www.126.com
    ServerAlias 126.com
    ErrorLog logs/www.126.com-error_log
    CustomLog logs/www.126.com-access_log common
</VirtualHost>
#========================================================
<VirtualHost *:80>
    DocumentRoot /webroot/uplooking
    ServerName www.uplooking.com
    ServerAlias uplooking.com
    ErrorLog logs/www.uplooking.com-error_log
    CustomLog logs/www.uplooking.com-access_log common
</VirtualHost>
#========================================================
<VirtualHost *:80>
    DocumentRoot /webroot/tianyun
    ServerName tianyun.com
    ServerAlias www.tianyun.com
    ErrorLog logs/www.tianyun.com-error_log
    CustomLog logs/www.tianyun.com-access_log common
</VirtualHost>

三、测试
[root@station230 ~]# links -dump http://www.126.com
   www.126.com
[root@station230 ~]# links -dump http://www.tianyun.com
   www.tianyun.com
[root@station230 ~]# links -dump http://www.uplooking.com
   www.uplooking.com

[root@station3 xen]# elinks www.yu01.com

============================================================
如何从客户端上传网站:FTP
server (httpd + ftp)
126:   站点主目录   ===>    /webroot/126   <=== 126 (管理账号)
[root@station230 ~]# useradd 126 -d /webroot/126/ -s /sbin/nologin
[root@station230 ~]# passwd 126
[root@station230 ~]# chown 126 /webroot/126/
[root@station230 ~]# ll -d /webroot/126/
drwxr-xr-x 2 126 root 4096 11-22 10:28 /webroot/126/
============================================================

实现访问控制:针对目录<Directory 目录></Directory>
基于主机:
基于用户:
示例:针对主网站目录设置访问控制
基于主机的访问控制
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
    Options Indexes FollowSymLinks     //Indexes索引目录,(没有默认主页时)。FollowSymLinks支持符号链接。
    AllowOverride None              
    Order allow,deny              
    Allow from all
</Directory>
========================================================================
如果AllowOverride All,又如果目录中有.htaccess文件,以.htaccess文件中设置为准

<Directory "/var/www/html">
    Options Indexes
    AllowOverride All          //允许目录中的.htaccess覆盖原有权限的设置
    Order allow,deny
    Allow from all
    Deny from 192.168.2.115
</Directory>

[root@station230 html]# pwd
/var/www/html
[root@station230 html]# cat .htaccess
    Order Deny,allow
    allow from all
=======================================================================

基于用户的访问:访问指定目录时需要用户名和密码
/var/www/html/download
==使用无格式文本文件
1. 建立口令文件
[root@station230 ~]# htpasswd -cm /etc/httpd/conf/webpasswd user1
New password:      输入密码
Re-type new password:  再输入密码
Adding password for user user1
-c 创建
-m MD5
[root@station230 ~]#
[root@station230 ~]# cat /etc/httpd/conf/webpasswd
user1:$apr1$tkLV4/..$BL2nd2Wbx4I5ZAf5uv8ZS.
[root@station230 ~]# htpasswd -m /etc/httpd/conf/webpasswd user2

2. 配置支持认证
[root@station230 html]# vim /etc/httpd/conf/httpd.conf 添加:
<Directory /var/www/html/download>
        AuthType basic
        AuthName "Please input password"
        AuthUserFile /etc/httpd/conf/webpasswd
        Require valid-user
</Directory>
[root@station230 html]# service httpd restart

==使用LDAP服务器认证

别名:
Alias /icons/ "/var/www/icons/"          //别名
       别名      真实目录

网站主目录:/var/www/html
需要访问的目录:/test
Alias /yang "/test"
<Directory "/test">     //访问权限应用于真实目录
        Options Indexes
        Order allow,deny
        Allow from all
</Directory>

测试:
[root@station230 ~]# links -dump http://192.168.2.115
   uplooking 01.


LAMP环境:
1. 搭建LAMP,测试  (源码安装,rpm包安装)
2. 上传网站
3. 创建数据库,并导入网站的数据库结构*.sql
   ==手动创建数据库
   ==网站的脚本自动创建数据库
4. 配置网站连接数据库(数据库服务器IP,数据库名,用户名,密码)

示例:Discuz!(php)
1. LAMP
[root@station230 ~]# yum -y install httpd mysql-server mysql php php-mysql gd
[root@station230 ~]# service httpd restart
[root@station230 ~]# service mysqld start
[root@station230 ~]# chkconfig mysqld on
[root@station230 ~]# chkconfig httpd on
[root@station230 ~]# mysql -uroot     不需要密码
[root@station230 ~]# mysqladmin -uroot password '123456'  设置密码(原来没有密码)
[root@station230 ~]# mysql -uroot -p123456
mysql> show databases;     查看当前的数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.01 sec)
测试LAMP:
[root@station230 ~]# cat /webroot/126/index.php 测试页面
<?
phpinfo();
?>

2. 上传网站
[root@station230 ~]# unzip Discuz_X2.5_SC_UTF8.zip
[root@station230 ~]# cd upload/
[root@station230 upload]# cp -rf * /webroot/126/
[root@station230 126]# pwd
/webroot/126
[root@station230 126]# chmod -R 777 .

3.安装网站(创建数据库,连接数据库)
http://192.168.2.115

[root@station230 ~]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| ultrax             |
+--------------------+
4 rows in set (0.00 sec)

mysql> use ultrax
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>
mysql>
mysql>
mysql> show tables;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值