lnmp安裝

                                          


                   http://pan.baidu.com/share/link?shareid=394225228&uk=1327557510
                                      LAMP安裝的通常步驟:
php的yum庫:yum install -y gcc-c++ zlib-devel  pcre-devel libjpeg-devel libpng-devel freetype-devel  libxml2-devel glibc-devel bzip2-devel curl-devel  openssl-develjavascript


php的編譯參數:./configure --prefix=/usr/local/php --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-config-file-path=/usr/local/php/etc --with-libxml-dir --with-openssl --with-zlib-dir --with-curl --with-pear --with-pcre-dir --with-gd --with-jpeg-dir --with-png-dir --with-mcrypt --with-freetype-dir --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-iconv-dir --enable-exif --enable-ftp --enable-fpm --enable-debug --enable-gd-native-ttf --enable-mbstring --enable-soap --disable-ipv6php


useradd -s /sbin/nologin -M php-fpm 先創建用戶    不然會出現【www】池不能查到php-fpm用戶
cp php.ini-production /usr/local/php/etc/php.ini 全局配置文件
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 啓動配置文件
cp /usr/local/php/etc/php-fpm.conf-default  /usr/local/php/etc/php-ftm.conf針對瀏覽器配置文件
。。。。。。/usr/local/php/sbin/php-fpm -t 安裝完後必須進行測試
vi /usr/local/php/config/php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/www.sock  #名字能夠自定義  靠這文件與nginx通訊  用來定義資源池所監聽的sock
user = php-fpm 用來定義php-fpm以哪一個用戶和組來運行
group =php-fpm
pm = dynamic  #動態的管理下面的內容 如pm=static是對於專用服務器 用於控制子進程數
pm.max_children = 50 #子進程最大有50個
pm.start_servers = 20 #最開始啓動20個
pm.min_spare_servers = 5 #空閒的時候最小不能低於5個
pm.max_spare_servers = 35 # 最多的時候不能多與35個子進程
pm.max_requests = 500 #一個子進程在一個生命週期內處理多少個請求而後銷燬
rlimit_files = 1024 #  每一個進程使用的文件描述符的限制(可調大一點)
針對慢查詢日誌
slowlog = /tmp/www_slow.log
request_slowlog_timout = 1
php_admin_value[open_basedir] = /data/www/:/tmp/  (多個目錄用:分開)設置網站域名訪問的根目錄。
php配置文件: 能夠有多個地址池。。。。。。。。css



nginx的參數配置:./configure --prefix=/usr/local/nginx --with-pcre --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module
。。。。。/usr/local/nginx/sbin/nginx -t 安裝完成後必定要測試html


由於vhosts目錄下自帶了默認的虛擬主機配置文件,訪問時候會自動跳轉到默認的虛擬主機,爲了安全起見咱們禁止全部的訪問,使其訪問咱們本身設置的網頁。添加default,表示默認主機;路徑修改成空目錄/tmp/1233/;deny all表示禁止全部訪問,會報403錯誤。java




nginx的參數配置:./configure --prefix=/usr/local/nginx --with-pcre --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_modulenode


在localhost下啓動文件:/usr/local/nginx/html/&fastcgi_script_name
nginx的啓動配置文件:vi /etc/init.d/nginx
#!/bin/bash
 # chkconfig: - 30 21
 # description: http service.
 # Source Function Library
 . /etc/init.d/functions
 # Nginx Settingsmysql


 NGINX_SBIN="/usr/local/nginx/sbin/nginx"
 NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
 NGINX_PID="/usr/local/nginx/logs/nginx.pid"
 RETVAL=0
 prog="Nginx"linux


 start() {
         echo -n $"Starting $prog: "
         mkdir -p /dev/shm/nginx_temp
         daemon $NGINX_SBIN -c $NGINX_CONF
         RETVAL=$?
         echo
         return $RETVAL
 }nginx


 stop() {
         echo -n $"Stopping $prog: "
         killproc -p $NGINX_PID $NGINX_SBIN -TERM
         rm -rf /dev/shm/nginx_temp
         RETVAL=$?
         echo
         return $RETVAL
 }c++


 reload(){
         echo -n $"Reloading $prog: "
         killproc -p $NGINX_PID $NGINX_SBIN -HUP
         RETVAL=$?
         echo
         return $RETVAL
 }


 restart(){
         stop
         start
 }


 configtest(){
     $NGINX_SBIN -c $NGINX_CONF -t
     return 0
 }


 case "$1" in
   start)
         start
         ;;
   stop)
         stop
         ;;
   reload)
         reload
         ;;
   restart)
         restart
         ;;
   configtest)
         configtest
         ;;
   *)
         echo $"Usage: $0 {start|stop|reload|restart|configtest}"
         RETVAL=1
 esac
 exit $RETVAL



NGINX的配置文件:vi /usr/local/nginx/conf/nginx.conf
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;


events
{
    use epoll;
    worker_connections 6000;
}


http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;
    include vhosts/*.conf;
}


NGINX下的網站配置
首先創建一個默認完整
server {
listen 80 default_server;
server_name localhost;
index index.html index.htm index.php;
root /tmp/cisco;
deny all;
}
新建一個虛擬主機目錄
server {
listen 80;  監聽的端口
server_name www.tt.com www.tt1.com;表示服務器網站
index index.html index.htm index.php
root /data/www
}
location ~ \.php {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_scription_name;
}


2.方法B(爲帶www的域名單獨設一條server規則)另外一種實現域名跳轉的方式:
rewrite ^(.*) http://tt.com$1 permanent; 直接在主目錄下添加
if ($host!='www.tt.com')域名跳轉:
{
rewrite ^/(.*)$ http://www.tt.com/$1 permanent;跳轉規則 (permanent永久重定向|break停止rewrite,再也不匹配|redirect 返回臨時重定向的http狀態|last基本上都用這個flag);
}
index index.html index.htm index.php php解析
root /data/www  主目錄
查看日誌格式再 neigx.conf中 該格式爲format
access_log /tmp/access.log format 日誌保存路徑及日誌格式名
禁止指定user-agent
if ( $http_user_agent ~* 'curl|baidu|sina')  其中*表示不區分大小寫
{
return 403;
}
測試方式:curl -A "qeasdrftgyhuj" -x192.168.0.109:80 www.test.com/forum.php -I
deny ip; 在全局下拒絕某個地址用於地址***
子頁面用戶認證  必須在主配置文件下進行(兩種方式)
location ~ .*admin\.php$  網站  或者 location ~/目錄/
     {
#auth_basic "cisco" 登錄提示名
#auth_basic_user_file /usr/local/nginx/etc/htpass 是密碼文件存放位置
deny ip 拒絕的地址
解析文件
fastcgi_pass unix:/tmp/www.sock
include pastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
      }
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
檢驗方式:curl -x127.0.0.1:80 -u user:passwd www.tt.com/admin.php



指定不記錄文件的類型 必須放在加密文件配置文件下面
查看日誌格式再 neigx.conf中 該格式爲format
access_log /tmp/access.log format 日誌保存路徑及日誌格式名
location ~ .*(gif|jpeg|png|bmp|jpg|swf|mp3|flv|zip|bz2|rar)$
{
access_log off;
expires 2d;   指定靜態文件的緩存時間
valid_referers none blocked *.bt.com *.btt.com    防盜鏈 在靜態文件圖片下
if ($invalid_referer)防盜鏈
{
return 403;防盜鏈
}
}


防盜鏈測試方式
curl -e "http://www.baidu.com" -I -x127.0.0.1:80 http://www.test.com/static/p_w_picpath/common/logo_88_31.gif


指定靜態文件的緩存時間
location ~\.(jss|cs)
{
access_log off;
expires 2d; 指定靜態文件的緩存時間


}


location ~ (static|cache)
{
access_log off;
}



nginx 代理服務器配置


upstream linux{
    server 代理服務器ip:80
    server 代理服務器ip:80
}
server {
listen 80;
server_name 代理網站名稱能夠有多個;


location / {
proxy_pass http://代理網站地址或者是 名稱 /;
proxy_set_header host $host;對於多個
#proxy_set_header x-real-ip $remote-addr;
    }
}




日誌切割(腳本)其中移動日誌的文件名必須和日誌格式中的文件名相同
vi /tmp/log.sh
!#/bin/bash
d=`date -d '-1 day' +%F`
[ -d /tmp/log ] || make /tmp/log ;判斷文件是否存在
mv /tmp/access.log /tmp/log/$d.log  從新生成新的日誌
/usr/local/nginx/sbin/nginx -s reload 或 /etc/init.d/nginx reload > /dev/null(在有啓動腳本的狀況下)
cd /tmp/log
gzip -f $d.log 壓縮日誌文件,不保留源文件




 
LNMP的擴展:      
                  隱藏apache版本信息
servertokens productonly
serversignature off
                   隱藏nginx版本信息
在nginx.conf 的http模塊下加入
server_tokens off;
                        隱藏php版本信息
 編輯php.ini
把expose_php = On 修改成  expose_php = Off



           nginx能夠經過HTTPLimitZoneModule和HTTPCoreModule兩個組件來對目錄進行限速。
http {
 limit_zone one $binary_remote_addr  10m;
 server {
 location /download/ {
 limit_conn  one 1;
 limit_rate 300k;
 }}}
limit_zone,是針對每一個IP定義一個存儲session狀態的容器。這個示例中定義了一個10m的容器,按照32bytes/session,能夠處理320000個session。limit_conn one 1;限制每一個IP只能發起一個併發鏈接。
limit_rate 300k;對每一個鏈接限速300k. 注意,這裏是對鏈接限速,而不是對IP限速。若是一個IP容許兩個併發鏈接,那麼這個IP就是限速limit_rate×2。
還能夠用來顯示每一個IP的併發數
nginx限制ip併發數,也是說限制同一個ip同時鏈接服務器的數量
1.添加limit_zone 這個變量只能在http使用
vi /usr/local/nginx/conf/nginx.conf
limit_zone one $remote_addr 10m;
2.添加limit_conn 這個變量能夠在http, server, location使用
我只限制一個站點,因此添加到server裏面
vim /usr/local/nginx/conf/vhost/taobap.cn.conf
limit_conn   one 10;
3.重啓nginx  killall -HUP nginx


              Linux下查看Nginx、Napache、MySQL、PHP的編譯參數的命令以下:
一、nginx編譯參數:
#/usr/local/nginx/sbin/nginx -V
 二、apache編譯參數:
# cat /usr/local/apache/build/config.nice
 三、php編譯參數:
# /usr/local/php/bin/php -i |grep configure
 四、mysql編譯參數:
# cat /usr/local/mysql/bin/mysqlbug|grep configure


nginx 設置自定義header                  
vim   nginx.conf                        
在http模塊中加入:                        
add_header  myheader  "the coments of myheader";
這裏的myheader 是自定義的名字,你本身隨便寫。
加完後,測試:curl  -I  http://IP
apache自定義header
 vi http.conf
<ifmodule mod_headers.c>
header add myheader "3242"
</ifmodule>
apache的404跳轉到首頁
Errordocument 404 /404.php


Nginx 404 跳轉至首頁
error_page 404 /404.php;
另外也能夠經過rewrite規則實現
 在 rewrite rule 的最後增長
if (!-e $request_filename) {
       rewrite ^(.*)$ /404.php last;
 }



Nginx中禁止訪問.txt文件    須要:stub_status模塊
location ~* \.(txt|doc)$
{ if (-f $request_filename)
{root /home/domain/public_html/test;
break;
} }
或者:location ~*\.(txt|doc)$
    {
    if  (-f $request_filename)
    return  403;
    }
$request_filename 當前鏈接請求的文件路徑,由root或alias指令與URI請求生成


Nginx出現413 Request Entity Too Large


處理Nginx出現的413 Request Entity Too Large錯誤這個錯誤通常在上傳文件的時候出現,打開nginx主配置文件nginx.conf,找到http{}段,添加client_max_body_size 8m;從新加載nginx的配置:nginx -t:kill -HUP nginx_pid要是跑php的話這個大小client_max_body_size要和php.ini中的以下值的最大值一致或者稍大,這樣就不會由於提交數據大小不一致出現的錯誤。post_max_size = 8M:upload_max_filesize = 2M重啓php-cgi:killall php_cgi:php_cgi start

相關文章
相關標籤/搜索