时间:2021-07-01 10:21:17 帮助过:21人阅读
CODE:
./configure
  make && make install
  cd ../2.        nginx 编译安装CODE:
./configure --user=www --group=www --prefix=/usr/local/nginx/
 --with-http_stub_status_module --with-openssl=/usr/local/openssl 
make && make install更详细的模块定制与安装请参照官方wiki. CODE:
# /usr/local/nginx/sbin/nginx -t  //Debug 配置文件的关键命令需要重点撑握.
2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 
2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully3、Nginx 启动:CODE:
# /usr/local/nginx/sbin/nginx4、Nginx
 配置文件修改重新加载:CODE:
# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`CODE:
$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri四、 Nginx RedirectCODE:
server
{
listen 80;
server_name linuxtone.org netseek.linuxtone.org;
index index.html index.php;
root /data/www/wwwroot;
if ($host !~ "^www\.linxtone\.org$") {
rewrite ^(.*) http://www.linuxtone.org$1 redirect;
}
........................
}五、 Nginx 目录自动加斜线:CODE:
if (-d $request_filename){
           rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
     }六  Nginx LocationCODE:
# Add expires header for static content
location ~* \.(js|css|jpg|jpeg|gif|png|swf)$ {
    if (-f $request_filename) {
       root /data/www/wwwroot/bbs;
       expires      1d;
       break;
    }
}2、根据判断某个目录CODE:
# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/  {
root    /data/www/wwwroot/down;
        expires 30d;
  }八、  Nginx 防盗链CODE:
#Preventing hot linking of images and other file
 types
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip)$ {
        valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost baidu.com;
if ($invalid_referer) {
      rewrite   ^/   ;
     # return   403;
      }
}2.        针对不同的目录CODE:
location /img/ {
    root /data/www/wwwroot/bbs/img/;
    valid_referers none blocked server_names *.linuxtone.org http://localhost baidu.com;
    if ($invalid_referer) {
                   rewrite  ^/  ;
                   #return   403;
    }
}3.        同实现防盗链和expires的方法CODE:
#Preventing hot linking of images and other file
 types
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip)$ {
        valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost ;
if ($invalid_referer) {
      rewrite   ^/   ;
                     }
     access_log off;
     root /data/www/wwwroot/bbs;
expires 1d;
     break;
}九、 Nginx 访问控制CODE:
#cd /usr/local/nginx/conf
#mkdir htpasswd
/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/tongji linuxtone 
#添加用户名为linuxtone
New password:   (此处输入你的密码)
Re-type new password:   (再次输入你的密码)
Adding password for user
http://count.linuxtone.org/tongji/data/index.html(目录存在/data/www/wwwroot/tongji/data/目录下)
将下段配置放到虚拟主机目录,当访问http://count.linuxtone/tongji/即提示要密验证:
location ~ ^/(tongji)/  {
                root    /data/www/wwwroot/count;
                        auth_basic              "LT-COUNT-TongJi";
                        auth_basic_user_file  /usr/local/nginx/conf/htpasswd/tongji;
                }2.        Nginx 禁止访问某类型的文件.CODE:
location ~* \.(txt|doc)$ {
   if (-f $request_filename) {
   root /data/www/wwwroot/linuxtone/test;
   #rewrite …..可以重定向到某个URL
   break;
   }
}方法2:CODE:
location ~* \.(txt|doc)${
        root /data/www/wwwroot/linuxtone/test;
        deny all;
}实例:CODE:
location ~ ^/(WEB-INF)/ { 
            deny all; 
}  3.        使用ngx_http_access_module限制ip访问CODE:
location / {
    deny    192.168.1.1;
    allow   192.168.1.0/24;
    allow   10.1.1.0/16;
    deny    all;
}详细参见wiki: http://wiki.codemongers.com/NginxHttpAccessModule#allowCODE:
limit_zone   linuxtone  $binary_remote_addr  10m;
server
       {
               listen       80;
               server_name  down.linuxotne.org;
               index index.html index.htm index.php;
               root   /data/www/wwwroot/down;
               #Zone limit
               location / {
                   limit_conn   linuxtone  1;
                   limit_rate  20k;
               }
..........
       }只允许客房端一个线程,每个线程20k.CODE:
location  /  {
    autoindex  on;
}6.        上文件大小限制CODE:
#!/bin/bash
log_dir="/data/logs"
time=`date +%Y%m%d`  
/bin/mv  ${log_dir}/access_linuxtone.org.log ${log_dir}/access_count.linuxtone.org.$time.log
kill -USR1 `cat  /var/run/nginx.pid`更多的日志分析与处理就关注(同时欢迎你参加讨论):http://bbs.linuxtone.org/forum-8-1.htmlCODE:
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path 缓存目录;其中,CODE:
proxy_pass:
if ( !-e $request_filename) {
    proxy_pass  http://mysvr;
}即改成有条件地去执行proxy_pass,这个条件就是当请求的文件在本地的proxy_temp_path指定的目录下不存在时,再向后端拉取。CODE:
upstream bbs.linuxtone.org {#定义负载均衡设备的Ip及设备状态
    server 127.0.0.1:9090 down;
    server 127.0.0.1:8080 weight=2;
    server 127.0.0.1:6060;
    server 127.0.0.1:7070 backup;
}在需要使用负载均衡的server中增加CODE:
……….
#loadblance my.linuxtone.org
       upstream  my.linuxtone.org  {
       ip_hash;
       server   127.0.0.1:8080;
       server   192.168.169.136:8080;
       server   219.101.75.138:8080;
       server   192.168.169.117;
       server   192.168.169.118;
       server   192.168.169.119;
     }
…………..
include          vhosts/linuxtone_lb.conf;
………
# vi proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
proxy_store on;
proxy_store_access   user:rw  group:rw  all:r;
#nginx cache               
#client_body_temp_path  /data/nginx_cache/client_body 1 2;
proxy_temp_path /data/nginx_cache/proxy_temp 1 2;#vi  linuxtone_lb.confCODE:
server
    {
        listen  80;
        server_name my.linuxtone.org;
        index index.php;
        root /data/www/wwwroot/mylinuxtone;
        if (-f $request_filename) {
            break;
           }
        if (-f $request_filename/index.php) {
          rewrite (.*) $1/index.php break;
        }
        error_page 403 http://my.linuxtone.org/member.php?m=user&a=login;
        location / {
           if ( !-e $request_filename) {
               proxy_pass http://my.linuxtone.org;
               break;
           }
           include /usr/local/nginx/conf/proxy.conf;
        }
}CODE:
CFLAGS=”$CFLAGS -g”注释掉或删掉这几行,重新编译即可。CODE:
#vi nginx-0.7.30/src/core/nginx.h
#define NGINX_VERSION      "1.8"
#define NGINX_VER          "LTWS/" NGINX_VERSION
#define NGINX_VAR          "NGINX"
#define NGX_OLDPID_EXT     ".oldbin"2) 修改nginx_http_header_filter_moduleCODE:
static char ngx_http_server_string[] = "Server:
 nginx" CRLF;修改为CODE:
static char ngx_http_server_string[] = "Server:
 LTWS" CRLF;a)        修改nginx_http_header_filter_moduleCODE:
static u_char ngx_http_error_full_tail[] =
"CODE:
static u_char ngx_http_error_tail[] =
"CODE:
static u_char ngx_http_error_full_tail[] =
"
404.png

curl.png
CODE:
# wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
# tar zxvf libunwind-0.99-alpha.tar.gz
# cd libunwind-0.99-alpha/
# CFLAGS=-fPIC ./configure
# make CFLAGS=-fPIC
# make CFLAGS=-fPIC install
# wget http://google-perftools.googlecode.com/files/google-perftools-0.98.tar.gz
# tar zxvf google-perftools-0.98.tar.gz
# cd google-perftools-0.98/
# ./configure
# make && make install
# echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
# ldconfig
# lsof -n | grep tcmalloc编译nginx 加载google_perftools_module:CODE:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000#使配置立即生效CODE:
#mkdir -p /data/www/wwwroot/nginx/{rrd,html}
#cd /usr/local/sbin
#wget http://www.nginx.eu/nginx-rrd/nginx-rrd-0.1.4.tgz
#tar zxvf nginx-rrd-0.1.4.tgz
#cd nginx-rrd-0.1.4
#cd etc/
#cp nginx-rrd.conf /etc
#cd etc/cron.d
#cp nginx-rrd.cron /etc/cron.d
#cd /usr/local/src/nginx-rrd-0.1.4/html
# cp index.php /data/www/wwwroot/nginx/html/
#cd /usr/local/src/nginx-rrd-0.1.4/usr/sbin
#cp * /usr/sbin/#vi /etc/nginx-rrd.confCODE:
#####################################################
#
# dir where rrd databases are stored
RRD_DIR="/data/www/wwwroot/nginx/rrd";
# dir where png images are presented
WWW_DIR="/data/www/wwwroot/nginx/html";
# process nice level
NICE_LEVEL="-19";
# bin dir
BIN_DIR="/usr/sbin";
# servers to test
# server_utl;server_name
SERVERS_URL="http://219.32.205.13/nginx_status;219.32.205.13  http://www.linuxtone.org/nginx_status;www.linuxtone.org""//根据你的具体情况做调整.CODE:
location /nginx_status {
stub_status on;
access_log off;
allow 192.168.1.37;
deny all;
}CODE:
# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
# wget http://forums.cacti.net/download.php?id=12676
# tar xvfz cacti-nginx.tar.gz
# cp cacti-nginx/get_nginx_socket_status.pl /data/cacti/scripts/
# cp cacti-nginx/get_nginx_clients_status.pl /data/cacti/scripts/
# chmod 755 /data/cacti/scripts/get_nginx*检测插件CODE:
# /data/cacti/scripts/get_nginx_clients_status.pl
 http://192.168.1.37/nginx_status在cacti管理面板导入CODE:
server {
listen 80;
server_name java.linuxtone.org
location / {
proxy_pass http://192.168.1.2:8080;
include /usr/local/nginx/conf/proxy.conf;
}
}6、如何关闭Nginx的LOG以上就介绍了Nginx 常见应用技术指南[Nginx Tips] 第二版,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。