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;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章