• Lnmp环境的自搭建


    ### 备选####

    安装开发者工具包 (简约版的可能要安装一下)

    yum groupinstall "Development tools"

    ##########

    1.准备 php函数的 rpm包
    yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

    2.准备lnmp源代码安装的所需要的源码包
    1).nginx http://nginx.org 下载
    wget http://nginx.org/download/nginx-1.5.13.tar.gz

    2).php http://php.net 下载

    3).mysql http://www.mysql.com 下载
    wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz

    4).libiconv http://www.gnu.org/software/libiconv/ 下载[http://ftp.gnu.org/gnu/libiconv/]
    wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

    5).libmcrypt
    http://sourceforge.net/projects/mcrypt/files/Libmcrypt/ 下载 [这个地址要FQ]

    6).mcrypt [google mcrypt download]
    http://sourceforge.net/projects/mcrypt/ 下载 [这个地址要FQ]
    /*
    configure不通过,提示:
    checking for mhash_keygen in -lmhash... no
    configure: error: "You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/"
    解决:
    export LD_LIBRARY_PATH=/home/felix021/lamp/libmcrypt/lib:/home/felix021/lamp/mhash/lib
    export LDFLAGS="-L/home/felix021/lamp/mhash/lib/ -I/home/felix021/lamp/mhash/include/"
    export CFLAGS="-I/home/felix021/lamp/mhash/include/"
    ./configure --prefix=/home/felix021/lamp/mcrypt/
    --with-libmcrypt-prefix=/home/felix021/lamp/libmcrypt
    */

    7).mhash
    http://sourceforge.net/projects/mhash/files/mhash/0.9.9/ 下载 [这个地址要FQ]

    8).pcre
    http://sourceforge.net/projects/pcre/files/pcre/ 下载 [这个地址要FQ]

    9).pdo_mysql
    http://pecl.php.net/package/PDO_MYSQL下载

    10).imagemagick
    http://www.imagemagick.org/script/download.php 下载[找亚洲的源,这样快点]

    11).imagick
    http://pecl.php.net/package/imagick

    12).memcache
    http://memcached.org/

    13).eaccelerator
    http://eaccelerator.net/

    3.安装 php-5.2.14 源代码包所需要的函数支持包
    tar zxvf libiconv-1.13.1.tar.gz
    cd libiconv-1.13.1/
    ./configure --prefix=/usr/local
    make
    make install

    tar zxvf libmcrypt-2.5.8.tar.gz
    cd libmcrypt-2.5.8/
    ./configure
    make
    make install

    cd libltdl/
    ./configure --enable-ltdl-install
    make
    make install

    tar zxvf mhash-0.9.9.9.tar.gz
    cd mhash-0.9.9.9/
    ./configure
    make
    make install

    ## 让支持包加入到内存中,使其别的软件能够找到
    vi /etc/ld.so.conf
    添加:
    /usr/local/lib 这行

    ldconfig 命令一下

    tar zxvf mcrypt-2.6.8.tar.gz
    cd mcrypt-2.6.8/
    ./configure
    make
    make install

    4.编译安装 MySQL
    mysql-5.5.3以前可以用
    ./configure --prefix=/usr/local/mysql --without-debug --enable-thread-safe-client --with-pthread --enable-assembler --enable-profiling --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-extra-charsets=all --with-plugins=all --with-mysqld-user=mysql --without-embedded-server --with-server-suffix=-community --with-unix-socket-path=/tmp/mysql.sock

    mysql5.5.3之后用cmake来安装
    1).安装cmake
    yum -y install cmake.i686
    2).安装mysql
    #建立mysql用户
    useradd -s /sbin/nologin mysql
    # cmake测试
    cmake -DMYSQL_USER=mysql -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.6 -DINSTALL_DATADIR=/data/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1

    #这之后步骤一样
    make
    make install

    #设置权限
    setfacl -m u:mysql:rxw -R /usr/local/mysql5.6
    setfacl -m d:u:mysql:rxw -R /usr/local/mysql5.6

    # 安装mysql和test数据库
    /usr/local/mysql5.6/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql5.6/ --datadir=/usr/local/mysql5.6/data

    # 启动mysql服务
    /usr/local/mysql5.6/bin/mysqld_safe --user=mysql & 或
    cp 源码包/support-files/mysql.server /etc/init.d/mysqld
    chkconfig --level 345 mysqld on
    service mysqld start

    # 修改msyql登陆root的密码
    /usr/local/mysql5.6/bin/mysqladmin -uroot -password "123456"

    # 用mysql登录
    /usr/local/mysql5.6/bin/mysql -uroot -p123

    #准备 mysql 配置文件
    cp /usr/local/mysql5.6/share/mysql/my-medium.cnf /etc/my.cnf 或
    cp 源码包/support-files/my-default.cnf /etc/my.cnf

    vi /etc/my.cnf
    #修改客户端和连接字符集 [client]
    default-character-set=utf8

    [mysqld]
    #修改服务器和数据库字符集
    character-set-server=utf8
    #修改服务器校验字符集
    collation-server=utf8

    #重启 mysql 服务让字符集生效
    pkill mysqld
    /usr/local/mysql5.6/bin/mysqld_safe --user=mysql &

    5. 编译安装 PHP(FastCGI 模式)

    cd php-5.2.14/
    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-opcache

    make ZEND_EXTRA_LIBS='-liconv'
    make install

    cp 源码包/php.ini-production /usr/local/php/etc/php.ini

    ,,,,,,

    6.准备编译安装 PHP5 扩展模块
    tar zxvf memcache-2.2.5.tgz
    cd memcache-2.2.5/
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config
    make
    make install

    tar jxvf eaccelerator-0.9.6.1.tar.bz2
    cd eaccelerator-0.9.6.1/
    /usr/local/php/bin/phpize
    ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
    make
    make install

    ar zxvf PDO_MYSQL-1.0.2.tgz
    cd PDO_MYSQL-1.0.2/
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
    make
    make install

    tar zxvf ImageMagick.tar.gz
    cd ImageMagick-6.5.1-2/
    ./configure
    make
    make install

    tar zxvf imagick-2.3.0.tgz
    cd imagick-2.3.0/
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config
    make
    make install

    7. 修改 php.ini 文件,让 php 模块生效
    cp /lnmp/php-5.2.14/php.ini-dist /usr/local/php/etc/php.ini
    vi php.ini
    extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
    extension = "memcache.so"
    extension = "pdo_mysql.so"
    extension = "imagick.so"

    再查找 output_buffering = Off
    修改为 output_buffering = On

    再查找; cgi.fix_pathinfo=0
    修改为 cgi.fix_pathinfo=0,防止 Nginx 文件类型错误解析漏洞

    8.在 php.ini中配置 eAccelerator加速 PHP
    mkdir -p /usr/local/eaccelerator_cache
    #准备 eaccelerator缓存目录

    Vi php.ini
    [eaccelerator]
    zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
    eaccelerator.shm_size="64"
    eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
    eaccelerator.enable="1"
    eaccelerator.optimizer="1"
    eaccelerator.check_mtime="1"
    eaccelerator.debug="0"
    eaccelerator.filter=""
    eaccelerator.shm_max="0"
    eaccelerator.shm_ttl="3600"
    eaccelerator.shm_prune_period="3600"
    eaccelerator.shm_only="0"
    eaccelerator.compress="1"
    eaccelerator.compress_level="9"

    9.准备 php-cgi 和 nginx进程执行者用户
    Useradd nginx

    10. 创建 php-fpm 配置文件- php-fpm.conf
    vi /usr/local/php/etc/php-fpm.conf
    <value name="display_errors">0</value>#0 改成 1,页面上会输出错误日志
    <value name="user">nginx</value>
    <value name="group">nginx</value>
    <value name="max_children">128</value>#最大子进程数 128,如果内存小于 2G,则 64 个最佳
    <value name="rlimit_files">65535</value>
    # Set open file desc rlimit,同时打开的文件数,linux 系统允许同时打开的文件数为 1024,修改
    linux 系统中允许同时打开的文件,ulimit -SHn 65535,而且这个参数重启后还能生效,加到/etc/profile 全局配置文件的最后,开机就会生效,ulimit -a 查看 open files 65535

    <value name="max_requests">1024</value>
    #最大请求数, How much requests each process should execute before respawn.一个子进程能够
    回应 1042 个请求

    11. 启动 php-cgi(fastcgi)进程,监听 127.0.0.1 的 9000 端口,进程数为 128(如果服务器内
    存小于 3GB,可以只开启 64个进程),用户和组为 nginx:
    #启动 php-cgi
    /usr/local/php/sbin/php-fpm start 也可以用 /usr/local/php/sbin/php-fpm
    #重新加载配置文件
    /usr/local/php/sbin/php-fpm reload
    #关闭 php-fpm,此时 nginx肯定不上 php
    /usr/local/php/sbin/php-fpm stop 或 pkill php-fpm

    12. 安装 Nginx 所需的 pcre 库
    tar zxvf pcre-8.10.tar.gz
    cd pcre-8.10/
    ./configure
    make && make install

    13. 安装 Nginx
    tar zxvf nginx-0.8.46.tar.gz
    cd nginx-0.8.46/
    ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    make && make install

    14. 修改 Nginx 配置文件
    vi /usr/local/nginx/conf/nginx.conf

    user nginx nginx;
    worker_processes 8; #相当于 cpu个数
    error_log logs/nginx_error.log
    pid /usr/local/nginx/nginx.pid;
    #Specifies the value for maximum file descriptors that can be opened by this process.
    worker_rlimit_nofile 65535;
    events
    {
    use epoll;
    worker_connections 65535;
    }

    http
    {
    include mime.types;
    default_type application/octet-stream;
    #charset gb2312;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;

    sendfile on;
    tcp_nopush on;

    keepalive_timeout 65;

    tcp_nodelay on;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    #limit_zone crawler $binary_remote_addr 10m;
    server
    {
    listen 80;
    server_name blog.s135.com;
    index index.html index.htm index.php;
    root /data0/htdocs/blog;

    #limit_conn crawler 20;

    location ~ .*.(php|php5)?$
    {
    #fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
    expires 30d;
    }

    location ~ .*.(js|css)?$
    {
    expires 1h;
    }
    log_format access '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" $http_x_forwarded_for';
    access_log /data1/logs/access.log access;
    }
    }

    fastcgi_connect_timeout:指定连接到后端FastCGI的超时时间。
    fastcgi_send_timeout:指定向FastCGI传送请求的超时时间,这个值是已经完成两次握手后向FastCGI传送请求的超时时间。
    fastcgi_read_timeout:指定接收FastCGI应答的超时时间,这个值是已经完成两次握手后接收FastCGI应答的超时时间。
    fastcgi_buffer_size:用于指定读取FastCGI应答第一部分需要用多大的缓冲区,这个值表示将使用1个64KB的缓冲区读取应答的第一部分(应答头),可以设置为fastcgi_buffers选项指定的缓冲区大小。
    fastcgi_buffers:指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答请求。如果一个PHP脚本所产生的页面大小为256KB,那么会为其分配4个64KB的缓冲区来缓存;如果页面大小大于256KB,那么大于256KB的部分会缓存到fastcgi_temp指定的路径中,但是这并不是好方法,因为内存中的数据处理速度要快于硬盘。一般这个值应该为站点中PHP脚本所产生的页面大小的中间值,如果站点大部分脚本所产生的页面大小为256KB,那么可以把这个值设置为“16 16k”、“4 64k”等。
    fastcgi_busy_buffers_size:的默认值是fastcgi_buffers的两倍。
    fastcgi_temp_file_write_size:表示在写入缓存文件时使用多大的数据块,默认值是fastcgi_buffers的两倍。
    fastcgi_cache:表示开启FastCGI缓存并为其指定一个名称。开启缓存非常有用,可以有效降低CPU的负载,并且防止502错误的发生,但是开启缓存也会引起很多问题,要视具体情况而定。
    fastcgi_cache_valid:fastcgi用来指定应答代码的缓存时间,实例中的值表示将200和302应答缓存一个小时,将301应答缓存1天,其他应答均缓存1分钟。

    15. 在/usr/local/nginx/conf/目录中创建 fastcgi_params 文件
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    #建议把 fastcgi_param写到 nginx.conf中而不是把它写到 fastcgi_params 配置文件中,否则配
    置不够灵活,比如后面默认 php 设置和 alias php 设置中,他们的 php 页面的系统地址是不
    同的,比如:
    默认 php 文件->/usr/local/nginx/html/index.php
    Alias php 文件->/mnt/bbs/index.php
    这个时候你会发现fastcgi_params中的SCRIPT_FILENAME的值是相同的,这样会导致alias
    php 的页面出不来,而配置在 nginx.conf中各自配置各自的 php 系统地址,这样比较灵活.

    #如果你觉得每个连接 php 的配置中都要加这一句话有点冗余,那就把它加入到
    fastcgi_params 文件中,这样只需要加一次,其他所有的 nginx.conf中的有关连接 fastcgi 的
    一块就不用加 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name这
    一句话了.

    16.配置开机启动 nginx,php-fpm,ulimit
    1)nginx
    Vi /etc/rc.local
    /usr/local/nginx/sbin/nginx
    2)php-fpm
    Vi /etc/rc.local
    /usr/local/php/sbin/php-fpm start
    3)ulimit
    Vi /etc/profile
    Ulimit -SHn 65535

    17.检查 nginx 配置文件语句错误
    /usr/local/nginx/sbin/nginx -t

    18.平滑重启 nginx 进程
    1)Pkill -HUP nginx
    2)kill -HUP `pgrep -uroot nginx`
    3)/usr/local/nginx/sbin/nginx -s reload

    19. 编写每天定时切割 Nginx 日志的脚本
    1、创建脚本/usr/local/nginx/sbin/cut_nginx_log.sh
    vi /usr/local/nginx/sbin/cut_nginx_log.sh

    #!/bin/bash
    # This script run at 00:00
    # The Nginx logs path
    logs_path="/usr/local/nginx/logs/"

    mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
    mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday"
    +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
    kill -USR1 `cat /usr/local/nginx/nginx.pid`


    2、设置 crontab,每天凌晨 00:00 切割 nginx 访问日志
    crontab -e
    00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh

    20.配置 nginx 虚拟主机
    Vi /usr/local/nginx/conf/nginx.conf
    == www.baidu.com公司网站
    server
    {
    listen 80;
    server_name www.baidu.com;
    index index.html index.php index.htm;
    root /web/baidu;
    location ~ .*.(php|php5)?$
    {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
    expires 30d;
    }
    #设置图片在客户端缓存时间为 30days
    location ~ .*.(js|css)?$
    {
    expires 1h;
    }
    #设置 js和 css 文件在客户端的缓存时间为 1hour
    log_format access '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" $http_x_forwarded_for';
    access_log logs/access.log access;
    #自定义日志区域
    }

    == www.sina.com公司网站

    server
    {
    listen 80;
    server_name www.sina.com;
    index index.html index.php index.htm;
    root /web/baidu;
    location ~ .*.(php|php5)?$
    {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
    expires 30d;
    }
    #设置图片在客户端缓存时间为 30days
    location ~ .*.(js|css)?$
    {
    expires 1h;
    }
    #设置 js和 css 文件在客户端的缓存时间为 1hour
    log_format access '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" $http_x_forwarded_for';
    access_log logs/access.log access;
    #自定义日志区域
    }

    最后在客户端测试虚拟主机 www.baidu.com和 www.sina.com两家公司网站

    21.列表页显示
    location / {
    autoindex on; #打开列表页
    root html;
    index index.html index.php index.htm;
    }
    /*
    autoindex on; #打开列表页
    autoindex_exact_size off;
    #默认为on,显示出文件的确切大小,单位是bytes。
    #改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
    autoindex_localtime on;
    #默认为off,显示的文件时间为GMT时间。
    #改为on后,显示的文件时间为文件的服务器时间


    可以把每个不同的网站用包含来写,里面就是写server{}这个,这样方便日志管理和修改,这个写在http{}这个最下面就可以了
    #include D:/wamp/nginx-1.0.4/conf/vhosts/tpshop.conf;
    #include D:/wamp/nginx-1.0.4/conf/vhosts/pmd.conf;
    */

    22.虚拟目录设置
    location /bbs{
    alias /mnt/bbs/;
    }
    #这样配置 html 静态文件是可以出来的,但是 php 动态页面出不来,而且会浏览器的页面上
    会显示" No input file specified. "的报错,其实是 php 系统文件地址( SCRIPT_FILENAME)找
    不到,也就是说 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    中的$document_root$fastcgi_script_name不是真正的/mnt/bbs/index.php 的地址,这可怎么解
    决:
    location /bbs {
    alias /mnt/bbs/;
    index bbs.php index.html index.php;
    }
    location ~ ^/bbs/ {
    root /mnt/;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    log_format bbs '$document_root$fastcgi_script_name ';
    access_log logs/bbs.access.log bbs;
    }
    #后面两行是关于日志的,就是为了更好的观察由 nginx 提交 fastcgi 的php 的系统地址
    SCRIPT_FILENAME,在这里我用$request_filename 来给 SCRIPT_FILENAME 赋值,在日志
    中的结果为/mnt/bbs/index.php,在这里我发现一个问题就是$request_filename 中的 root 设置
    为/mnt,否则$request_filename 的值为:/mnt/bbs/bbs/index.php.

    由以上可以得到一个结论,就是默认 php 设置也可以这样设置关于 SCRIPT_FILENAME:
    location ~ .php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    log_format php '$document_root$fastcgi_script_name ';
    access_log logs/php.access.log php;
    }
    #此时从日志中可以看到,$request_filename 的值为/usr/local/nginx/html/index.php,而以前默
    认的/scripts$fastcgi_script_name显然是错的 php 系统地址,日志中显示为/scripts/index.php


    23.nginx 状态监控
    location /nginxstatus{
    stub_status on;
    access_log off;
    }
    #客户端访问网址:http://www.baidu.com/nginxstatus

    24.rewrite 正则过滤
    location ~ .php$ {
    proxy_pass http://127.0.0.1;
    }
    Rewrite 指令最后一项参数为 flag 标记,支持的 flag 标记如下:
    Last 标示完成 rewrite 规则
    Break 不再匹配后面的规则
    Redirect 302临时重定向
    Permanent 301 永久重定向
    Last 和break用来实现 uri重写,浏览器地址栏的 url地址不变,但在服务器访问的路径发
    了变化,redirect 和permanent 用来实现 url 跳转,浏览器地址栏会显示跳转后的 url 地址
    使用 alias 指令时必须使用 last 标记,使用 proxy_pass 指令时要使用 break 标记,last 标记
    本条 rewrite规则执行完毕后,会对其所在的 server{}标签重新发起请求,而 break 标记则
    本条规则匹配完成后,终止匹配,不再匹配后面的规则.

    在匹配的过程中,nginx将首先匹配字符串,然后再匹配正则表达式,匹配到第一个正则
    达式后,会停止搜索,如果匹配到正则表达式,则使用正则表达式的搜索结果,如果没有
    配到正则表达式,则使用字符串的搜索结果.
    可以使用前缀"^~"来禁止匹配到字符串后,再去检查正则表达式,匹配到 url 后,将停止
    询.
    使用前缀"="可以进行精确的 url 匹配,如果找到匹配的 uri,则停止查询,例如"location=
    只能匹配到"/",而"/test.html"则不能被匹配.
    正则表达式的匹配,按照它们在配置文件中的顺序进行,写在前面的优先.
    Location = / {
    #仅仅匹配 /
    [configuration A]
    }
    Location / {
    #匹配任何以/开头的查询,但是正则表达式及较长的字符串(/bbs/)将被优先匹配.
    [configuration B]
    }
    Location ^~ /images/ {
    #匹配任何以/images/开头的字符串,并且停止搜索,所以正则表达式将不会被检查.
    [configuration C]

    }
    Location ~* .(gif|jpg|jpeg)$ {
    #匹配以.gif、.jpg、.jpeg 结尾的任何请求,但是,/images/内的请求将使用 configurati
    c 的配置
    [configuratoin D]
    }
    请求处理匹配结果示例:
    / -> configuration A;
    /documents/document.html -> configuration B;
    /images/1.gif -> configuration c;
    /documents/1.jpg -> configuration D;


    25.支持phpinfo模式
    set $path_info "";
    set $real_script_name $fastcgi_script_name;
    if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
    set $real_script_name $1;
    set $path_info $2;
    }
    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
    fastcgi_param SCRIPT_NAME $real_script_name;
    fastcgi_param PATH_INFO $path_info;
    #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;

    #fastcgi_param SCRIPT_NAME $fastcgi_script_name;

    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT $document_root;
    fastcgi_param SERVER_PROTOCOL $server_protocol;

    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;

    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param REDIRECT_STATUS 200; # 或以注释这句 #

    ##############################################################################

    yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers


    #nginx所需要的库文件件
    yum -y install pcre-devel zlib-devel

    #PHP依赖的库文件
    yum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel


    安装库文件
    tar zxvf libiconv-1.14.tar.gz
    cd libiconv-1.14
    ./configure --prefix=/usr/local
    make && make install


    tar zxvf libmcrypt-2.5.8.tar.gz
    cd libmcrypt-2.5.8
    ./configure
    make && make install

    /sbin/ldconfig

    cd libltdl
    ./configure --enable-ltdl-install
    make && make install

    tar zxvf mhash-0.9.9.9.tar.gz
    cd mhash-0.9.9.9/
    ./configure
    make && make install

    ## 让支持包加入到内存中,使其别的软件能够找到
    vi /etc/ld.so.conf
    添加: /usr/local/lib 这行
    /sbin/ldconfig

    tar -zxvf mcrypt-2.6.8.tar.gz
    cd mcrypt-2.6.8/
    ./configure
    make && make install

    # 安装php
    tar zxvf php-5.4.0.tar.gz
    cd php-5.4.0.tar.gz
    ./configure --prefix=/usr/local/php5.4
    --with-config-file-path=/etc
    --with-iconv-dir=/usr/local/ --with-freetype-dir
    --with-mysql=/usr/local/mysql
    --with-mysqli=/usr/local/mysql/bin/mysql_config
    --with-jpeg-dir --with-png-dir --with-zlib
    --with-mhash --enable-sockets --enable-ftp
    --with-libxml-dir --enable-xml --disable-rpath
    --enable-bcmath
    --enable-shmop --enable-sysvsem
    --enable-inline-optimization --with-curl
    --with-curlwrappers
    --enable-mbregex
    --enable-mbstring --with-mcrypt --with-gd
    --enable-gd-native-ttf --with-openssl --with-mhash
    --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl
    --enable-fpm
    --with-xmlrpc --enable-zip --enable-soap
    --without-pear

    make ZEND_EXTRA_LIBS='-liconv'
    make install

    cp php.ini-production /etc/php.ini

    将php-fpm 作为服务运行
    cp /soft/php-5.4/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod 755 /etc/init.d/php-fpm
    chkconfig --add php-fpm
    chkconfig --level 345 php-fpm on
    服务方式启动php-fpm
    service php-fpm start


    【2】编译Nginx
    安装pcre
    tar zxvf pcre-8.32.tar.gz
    cd pcre-8.32/
    ./configure --prefix=/usr/local/pcre
    make && make install
    安装nginx
    tar zxvf nginx-1.0.15.tar.gz
    cd nginx-1.0.15/

    ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6
    make && make install

  • 相关阅读:
    nginx学习1
    win7右下角的网络连接图标不见了~终极必杀技
    centos配置history记录每个用户执行过的命令
    Screen会话命令 Linux
    Linux的运行级别和chkconfig用法
    Linux与Windows中的UTC时间
    Solr 缓存配置
    SolrJ 查询数据
    Solr之困
    solr 查询参数说明
  • 原文地址:https://www.cnblogs.com/ahwu/p/3656553.html
Copyright © 2020-2023  润新知