LDAP

===============WEB服务================

静态网站:*.html *.htm


动态网站:*.php *.jsp *.cgi *.asp

PHP:

LAMP: Linux + Apache + Mysql +PHP/Perl/Python

LNMP(LEMP): Linux + Nginx + Mysql + PHP(FastCGI)


JSP:

Tomcat

Apache + Tomcat (虚拟主机:1.静态   2.jsp)

LAMP + Tomcat <===

Nginx + Tomcat

IBM WebSphere


Web服务器软件:

Apache、Nginx、IIS、Tomcat、Lighttpd、IBMWebSphere

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


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  默认测试页面


[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 willsee 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

[root@localhost html]# cat 3.php

<?

phpinfo();

?>



配置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安装目录

KeepAlive Off           //是否允许持久性连接

MaxKeepAliveRequests 100

KeepAliveTimeout 15


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的用户组


两种运行模式:

[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个父进程,10个子进程)

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]# 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">

   OptionsIndexes FollowSymLinks  //Indexes索引目录,(没有默认主页时)

                     FollowSymLinks支持符号链接

  AllowOverride None          

   Orderallow,deny            

   Allow fromall

</Directory>

DirectoryIndex index.html index.html.var//设置默认主页

ErrorLog logs/error_log         //错误日志

CustomLog logs/access_log combined  //访问日志

Alias /icons/ "/var/www/icons/"     //别名

AddDefaultCharset UTF-8         //字符集



### 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

www.baidu.com       192.168.2.252   /webroot/baidu


一、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

   ServerNamewww.126.com

   ServerAlias126.com

   ErrorLoglogs/www.126.com-error_log

   CustomLoglogs/www.126.com-access_log common

</VirtualHost>

#========================================================

<VirtualHost *:80>

   DocumentRoot/webroot/uplooking

   ServerNamewww.uplooking.com

   ServerAliasuplooking.com

   ErrorLoglogs/www.uplooking.com-error_log

   CustomLoglogs/www.uplooking.com-access_log common

</VirtualHost>

#========================================================

<VirtualHost *:80>

   DocumentRoot/webroot/tianyun

   ServerNametianyun.com

   ServerAliaswww.tianyun.com

   ErrorLoglogs/www.tianyun.com-error_log

   CustomLoglogs/www.tianyun.com-access_log common

</VirtualHost>


============基于IP + 基于主机名===========

NameVirtualHost 192.168.2.180:80


<VirtualHost192.168.2.180:80>

   DocumentRoot /webroot/126

   ServerNamewww.126.com              192.168.2.180

   ServerAlias126.com

   ErrorLoglogs/126.com-error_log

   CustomLoglogs/126.com-access_log common

</VirtualHost>

#=============================================

<VirtualHost 192.168.2.180:80>

   DocumentRoot/webroot/tianyun

   ServerName www.tianyun.com              192.168.2.180

   ServerAliastianyun.com

   ErrorLoglogs/tianyun.com-error_log

   CustomLoglogs/tianyun.com-access_log common

</VirtualHost>

#=============================================

<VirtualHost 192.168.2.182:80>

   DocumentRoot/webroot/baidu

   ServerName www.baidu.com                192.168.2.182

   ServerAliasbaidu.com

   ErrorLoglogs/baidu.com-error_log

   CustomLoglogs/baidu.com-access_log common

</VirtualHost>

#=============================================

<VirtualHost 192.168.2.183:80>

   DocumentRoot/webroot/sina

   ServerNamewww.sina.com             192.168.2.183

   ServerAliassina.com

   ErrorLoglogs/sina.com-error_log

   CustomLoglogs/sina.com-access_log common

</VirtualHost>

#=============================================

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


三、测试

[root@station230 ~]# links-dump http://www.126.com

  www.126.com

[root@station230 ~]# links -dumphttp://www.tianyun.com

 www.tianyun.com

[root@station230 ~]# links -dumphttp://www.uplooking.com

 www.uplooking.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">

   OptionsIndexes FollowSymLinks  //Indexes索引目录,(没有默认主页时)

                     FollowSymLinks支持符号链接

   AllowOverrideNone          

   Orderallow,deny            

   Allow fromall

</Directory>

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

扩展:

如果AllowOverride All,又如果目录中有.htaccess文件,以.htaccess文件中设置为准


<Directory "/var/www/html">

   Options Indexes

  AllowOverride All       //允许目录中的.htaccess覆盖原有权限的设置

   Orderallow,deny

   Allow fromall

   Deny from192.168.2.115

</Directory>


[root@station230 html]# pwd

/var/www/html

[root@station230 html]# cat .htaccess

   OrderDeny,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

       Requirevalid-user

</Directory>

[root@station230 html]# servicehttpd restart



==使用LDAP服务器认证

LDAP服务器: 192.168.2.100

Base DN: dc=tianyun,dc=com

<Directory /var/www/html/download>

AuthType basic

       AuthName"ladp auth test"

      AuthLDAPUrl "ldap://192.168.2.100/dc=tianyun,dc=com"

       Requirevalid-user

</Directory>



别名:访问网站主目录以外的目录

Alias /icons/ "/var/www/icons/"     //别名

别名真实目录


网站主目录:/var/www/html

需要访问的目录:/test

# echo "Alias" > /test/index.html

Alias /yang "/test"

<Directory "/test"> //访问权限应用于真实目录

       OptionsIndexes

       Orderallow,deny

       Allowfrom all

</Directory>


测试:

[root@station230 ~]# links -dumphttp://192.168.2.115/yang





LAMP环境:

1. 搭建LAMP,测试(源码安装,rpm包安装)

2. 上传网站

3. 创建数据库,并导入网站的数据库结构*.sql

  ==手动创建数据库

  ==网站的脚本自动创建数据库

4. 配置网站连接数据库(数据库服务器IP,数据库名,用户名,密码)


示例:Discuz!(php)

1. LAMP

[root@station230 ~]# yum -y install httpd mysql-servermysql php php-mysql gd

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

[root@station230 ~]# yum -y install httpd* mysql* php*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 ~]# unzipDiscuz_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 thebuffer.


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 andcolumn names

You can turn off this feature to get a quicker startupwith -A


Database changed

mysql>

mysql>

mysql>

mysql> show tables;


你可能感兴趣的:(linux,网站,动态,虚拟主机)