CODE:
./configure<code>./configure<br> make && make install<br> cd ../
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 <br>make && make install
./configure --user=www --group=www - - 접두사=/usr/local/nginx/
--with-http_stub_status_module --with-openssl=/usr/local/openssl <span>make && make install</span>
자세한 모듈 사용자 정의 및 설치는 공식 위키를 참조하세요# /usr/local/nginx/sbin/nginx -t //Debug 配置文件的关键命令需要重点撑握.<br>2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok <br>2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
# /usr/local/nginx/sbin/nginx -t //디버그 구성 파일의 주요 명령은 다음과 같습니다. 마스터하세요.<span>2008/12/16 09:08:35 [info] 28412#0: 구성 파일 /usr/local/nginx/conf/nginx.conf 구문은 괜찮습니다 </span>2008/12/16 09 :08:35 [info] 28412#0: /usr/local/nginx/conf/nginx.conf 구성 파일이 성공적으로 테스트되었습니다.
3 Nginx 시작:
# /usr/local/nginx/sbin/nginx
CODE:4. 구성 파일 수정 및 다시 로드:
# kill -HUP `cat /usr/local/nginx/logs/nginx.pid
CODE:3. Nginx에서 사용할 수 있는 일부 전역 변수는 조건부 판단에 사용될 수 있습니다:
$args<br>$content_length<br>$content_type<br>$document_root<br>$document_uri<br>$host<br>$http_user_agent<br>$http_cookie<br>$limit_rate<br>$request_body_file<br>$request_method<br>$remote_addr<br>$remote_port<br>$remote_user<br>$request_filename<br>$request_uri<br>$query_string<br>$scheme<br>$server_protocol<br>$server_addr<br>$server_name<br>$server_port<br>$uri
CODE:$args
$content_length$host
$http_user_agentserver<br>{<br>listen 80;<br>server_name linuxtone.org netseek.linuxtone.org;<br>index index.html index.php;<br>root /data/www/wwwroot;<br>if ($host !~ "^www.linxtone.org$") {<br>rewrite ^(.*) http://www.linuxtone.org redirect;<br>}<br>........................<br>}
$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$uri4. Nginx 리디렉션 모든 linuxtone.org 및 netseek.linuxtone.org 도메인 이름을 http://www.linuxtone.org로 리디렉션합니다. 코드:서버{listen 80;server_name linuxtone.org netseek.linuxtone.org;index index.html index.php;root /data/www/wwwroot;if ($host !~ "^www.linxtone.org$") {^(.*) http://www.linuxtone.org$1 리디렉션 다시 작성;}...................}
5. Nginx 디렉토리는 자동으로 슬래시를 추가합니다.코드:if (-d $request_filename){<br> rewrite ^/(.*)([^/])$ http://$host// permanent;<br> }
6개의 Nginx 위치# 정적 콘텐츠에 대한 만료 헤더 추가
# Add expires header for static content<br>location ~* .(js|css|jpg|jpeg|gif|png|swf)$ {<br> if (-f $request_filename) {<br> root /data/www/wwwroot/bbs;<br> expires 1d;<br> break;<br> }<br>}
if (-f $request_filename) { root /data/www/wwwroot/bbs; 1d 만료;break;
}# serve static files<br>location ~ ^/(images|javascript|js|css|flash|media|static)/ {<br>root /data/www/wwwroot/down;<br> expires 30d;<br> }
}2, 디렉토리 판단 기준 # 정적인 파일 제공
위치 ~ ^/(images|javascript|js|css|flash|media|static)/ { root /data/www/wwwroot/down;
30일 만료;#Preventing hot linking of images and other file
types<br>location ~* ^.+.(gif|jpg|png|swf|flv|rar|zip)$ {<br> valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost baidu.com;<br>if ($invalid_referer) {<br> rewrite ^/ ;<br> # return 403;<br> }<br>}
}8. Nginx 안티 핫링크1. 유형location /img/ {<br> root /data/www/wwwroot/bbs/img/;<br> valid_referers none blocked server_names *.linuxtone.org http://localhost baidu.com;<br> if ($invalid_referer) {<br> rewrite ^/ ;<br> #return 403;<br> }<br>}
CODE:#이미지 및 기타 파일의 핫링크 방지
유형<p>위치 ~* ^.+.(gif|jpg|png|swf|flv|rar|zip)$ {</p> 유효한_참조 없음 차단됨 server_names *.linuxtone.org linuxtone.org http://localhost baidu. com;<code>#Preventing hot linking of images and other file
types<br>location ~* ^.+.(gif|jpg|png|swf|flv|rar|zip)$ {<br> valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost ;<br>if ($invalid_referer) {<br> rewrite ^/ ;<br> }<br> access_log off;<br> root /data/www/wwwroot/bbs;<br>expires 1d;<br> break;<br>}
if ($invalid_referer) { rewrite ^/ ; # return 403;위치 /img/ { 루트 /data/www/wwwroot/bbs/img/; valid_referers 없음 차단됨 server_names *.linuxtone.org http://localhost baidu com. ; if ($invalid_referer) { rewrite ^/ ; #return 403; }}
3. CODE:#이미지 및 기타 파일의 핫링크 방지
유형 <o> 위치 ~ * ^.+. (GIF | JPG | PNG | SWF | FLV | RAR | ZIP) $ { Valid_referrs 없음 차단된 Server_names * .linuxTone.org Linuxtone.org Calhost; $invalid_referer) { 다시 쓰기 ^/ ; } access_log off; root /data/www/wwwroot/bbs;1d 만료; break;}9. Nginx 접근 제어1. Nginx ID 확인CODE:<code>#cd /usr/local/nginx/conf<br>#mkdir htpasswd<br>/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/tongji linuxtone <br>#添加用户名为linuxtone<br>New password: (此处输入你的密码)<br>Re-type new password: (再次输入你的密码)<br>Adding password for user<br>http://count.linuxtone.org/tongji/data/index.html(目录存在/data/www/wwwroot/tongji/data/目录下)<br>将下段配置放到虚拟主机目录,当访问http://count.linuxtone/tongji/即提示要密验证:<br>location ~ ^/(tongji)/ {<br> root /data/www/wwwroot/count;<br> auth_basic "LT-COUNT-TongJi";<br> auth_basic_user_file /usr/local/nginx/conf/htpasswd/tongji;<br> }
2. Nginx는 특정 유형의 파일에 대한 접근을 금지합니다.코드:
위치 ~* .(txt|doc)$ {<code>location ~* .(txt|doc)$ {<br> if (-f $request_filename) {<br> root /data/www/wwwroot/linuxtone/test;<br> #rewrite …..可以重定向到某个URL<br> break;<br> }<br>}
if (-f $request_filename) { root /data/www/wwwroot/linuxtone/test; #rewrite…..ok URL로 리디렉션break;
}location ~* .(txt|doc)${<br> root /data/www/wwwroot/linuxtone/test;<br> deny all;<br>}
}방법 2:위치 ~ * .(txt| doc)${
> 🎜>CODE:위치 ~ ^/(WEB-INF)/ {
location ~ ^/(WEB-INF)/ { <br> deny all; <br>}
코드:위치 / {<p> 192.168.1.1 거부;</p> 192.168.1.0/24 허용;<code>location / {<br> deny 192.168.1.1;<br> allow 192.168.1.0/24;<br> allow 10.1.1.0/16;<br> deny all;<br>}
10.1.1.0/16 허용; 모두 거부; }4. Nginx 다운로드는 동시성 및 속도를 제한합니다
limit_zone linuxtone $binary_remote_addr 10m;<br>server<br> {<br> listen 80;<br> server_name down.linuxotne.org;<br> index index.html index.htm index.php;<br> root /data/www/wwwroot/down;<br> #Zone limit<br> location / {<br> limit_conn linuxtone 1;<br> limit_rate 20k;<br> }<br>..........<br> }
CODE :limit_zone linuxtone $binary_remote_addr 10m;
serverlimit_rate 20k; ........ .
}location / {<br> autoindex on;<br>}
객실에서는 스레드 하나만 허용되며 각 스레드는 20k입니다.location / {<span> autoindex on;} </span>
6. #!/bin/bash<br>log_dir="/data/logs"<br>time=`date +%Y%m%d` <br>/bin/mv ${log_dir}/access_linuxtone.org.log ${log_dir}/access_count.linuxtone.org.$time.log<br>kill -USR1 `cat /var/run/nginx.pid`
더 많은 로그 분석 및 처리에 대해 관심을 가져주세요(토론에 참여하셔도 좋습니다):http://bbs.linuxtone.org/forum-8-1.htmlCODE:
proxy_store on;<code>proxy_store on;<br>proxy_store_access user:rw group:rw all:rw;<br>proxy_temp_path 缓存目录;
proxy_store_access 사용자: rw group:rw all:rw;proxy_temp_path 캐시 디렉터리;그 중 proxy_pass:<br>if ( !-e $request_filename) {<br> proxy_pass http://mysvr;<br>}
proxy_pass:<span>if( !-e $request_filename)를 수정해야 합니다. {</span>proxy_pass http://mysvr;<br>}
즉, Proxy_pass를 조건부로 실행하도록 변경됩니다. 이 조건은 요청한 파일이 지정한 디렉터리에 없을 때입니다. 로컬 Proxy_temp_path는 백엔드에서 가져옵니다. upstream bbs.linuxtone.org {#定义负载均衡设备的Ip及设备状态<br> server 127.0.0.1:9090 down;<br> server 127.0.0.1:8080 weight=2;<br> server 127.0.0.1:6060;<br> server 127.0.0.1:7070 backup;<br>}
CODE:upstream bbs. linuxtone.org {#로드 밸런싱 장치의 IP 및 장치 상태 정의 <br> server 127.0.0.1:9090 down;<span> server 127.0.0.1:8080 Weight=2;</span> server 127.0.0.1:6060; <span> 서버 127.0.0.1:7070 백업;</span>}
……….<br>#loadblance my.linuxtone.org<br> upstream my.linuxtone.org {<br> ip_hash;<br> server 127.0.0.1:8080;<br> server 192.168.169.136:8080;<br> server 219.101.75.138:8080;<br> server 192.168.169.117;<br> server 192.168.169.118;<br> server 192.168.169.119;<br> }<br>…………..<br>include vhosts/linuxtone_lb.conf;<br>………<br># vi proxy.conf<br>proxy_redirect off;<br>proxy_set_header Host $host;<br>proxy_set_header X-Real-IP $remote_addr;<br>proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>client_max_body_size 50m;<br>client_body_buffer_size 256k;<br>proxy_connect_timeout 30;<br>proxy_send_timeout 30;<br>proxy_read_timeout 60;<br>proxy_buffer_size 4k;<br>proxy_buffers 4 32k;<br>proxy_busy_buffers_size 64k;<br>proxy_temp_file_write_size 64k;<br>proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;<br>proxy_max_temp_file_size 128m;<br>proxy_store on;<br>proxy_store_access user:rw group:rw all:r;<br>#nginx cache <br>#client_body_temp_path /data/nginx_cache/client_body 1 2;<br>proxy_temp_path /data/nginx_cache/proxy_temp 1 2;
#vi linuxtone_lb.confCODE:
server<br> {<br> listen 80;<br> server_name my.linuxtone.org;<br> index index.php;<br> root /data/www/wwwroot/mylinuxtone;<br> if (-f $request_filename) {<br> break;<br> }<br> if (-f $request_filename/index.php) {<br> rewrite (.*) /index.php break;<br> }<br> error_page 403 http://my.linuxtone.org/member.php?m=user&a=login;<br> location / {<br> if ( !-e $request_filename) {<br> proxy_pass http://my.linuxtone.org;<br> break;<br> }<br> include /usr/local/nginx/conf/proxy.conf;<br> }<br>}
CODE:
CFLAGS=”$CFLAGS -g”
이 줄을 주석 처리하거나 삭제하고 다시 컴파일하세요. CODE:
#vi nginx- 0.7 .30/src/core/nginx.h<code>#vi nginx-0.7.30/src/core/nginx.h<br>#define NGINX_VERSION "1.8"<br>#define NGINX_VER "LTWS/" NGINX_VERSION<br>#define NGINX_VAR "NGINX"<br>#define NGX_OLDPID_EXT ".oldbin"
#define NGINX_VERSION "1.8"#define NGINX_VER "LTWS/" NGINX_VERSION#define NGINX_VAR "NGINX"static char ngx_http_server_string[] = "Server:
nginx" CRLF;
CODE: 수정됨 static char ngx_http_server_string[] = "Server:
LTWS" CRLF;
CODE:static u_char ngx_http_error_full_tail[] =<br>"
static u_char ngx_http_error_full_tail[] =
" " CRLF
"" CRLFstatic u_char ngx_http_error_tail[] =<br>"
;
static u_char ngx_http_error_tail[] =
;
수정됨:코드:static u_char ngx_http_error_full_tail[] =<br>"
404.png
curl.png
CODE:
# wget http: //download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz# wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz<br># tar zxvf libunwind-0.99-alpha.tar.gz<br># cd libunwind-0.99-alpha/<br># CFLAGS=-fPIC ./configure<br># make CFLAGS=-fPIC<br># make CFLAGS=-fPIC install<br># wget http://google-perftools.googlecode.com/files/google-perftools-0.98.tar.gz<br># tar zxvf google-perftools-0.98.tar.gz<br># cd google-perftools-0.98/<br># ./configure<br># make && make install<br># echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf<br># ldconfig<br># lsof -n | grep tcmalloc
# tar zxvf libunwind-0.99-alpha.tar.gz# cd libunwind -0.99-alpha/# CFLAGS=-fPIC ./configurenet.ipv4.tcp_fin_timeout = 30<br>net.ipv4.tcp_keepalive_time = 300<br>net.ipv4.tcp_syncookies = 1<br>net.ipv4.tcp_tw_reuse = 1<br>net.ipv4.tcp_tw_recycle = 1<br>net.ipv4.ip_local_port_range = 5000 65000
# 구성 즉시 적용 #mkdir -p /data/ www /wwwroot/nginx/{rrd,html}
#mkdir -p /data/www/wwwroot/nginx/{rrd,html}<br>#cd /usr/local/sbin<br>#wget http://www.nginx.eu/nginx-rrd/nginx-rrd-0.1.4.tgz<br>#tar zxvf nginx-rrd-0.1.4.tgz<br>#cd nginx-rrd-0.1.4<br>#cd etc/<br>#cp nginx-rrd.conf /etc<br>#cd etc/cron.d<br>#cp nginx-rrd.cron /etc/cron.d<br>#cd /usr/local/src/nginx-rrd-0.1.4/html<br># cp index.php /data/www/wwwroot/nginx/html/<br>#cd /usr/local/src/nginx-rrd-0.1.4/usr/sbin<br>#cp * /usr/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#####################################################<br>#<br># dir where rrd databases are stored<br>RRD_DIR="/data/www/wwwroot/nginx/rrd";<br># dir where png images are presented<br>WWW_DIR="/data/www/wwwroot/nginx/html";<br># process nice level<br>NICE_LEVEL="-19";<br># bin dir<br>BIN_DIR="/usr/sbin";<br># servers to test<br># server_utl;server_name<br>SERVERS_URL="http://219.32.205.13/nginx_status;219.32.205.13 http://www.linuxtone.org/nginx_status;www.linuxtone.org""
# cd etc/cron.d#cp nginx-rrd.cron /etc/cron.d#cd /usr/local/src/nginx-rrd-0.1.4/html##################### #########################<span>#</span># rrd 데이터베이스가 저장된 디렉토리<span>RRD_DIR="/ data/ www/wwwroot/nginx/rrd";</span># png 이미지가 표시되는 디렉토리<br>WWW_DIR="/data/www/wwwroot/nginx/html";<span># 프로세스 좋은 수준</span>NICE_LEVEL =" -19";<br># bin dir<span>BIN_DIR="/usr/sbin";</span>테스트할 서버 #개<br># server_utl;server_name<span>SERVERS_URL="http://219.13/ nginx_status;219.32.205.13 http://www.linuxtone.org/nginx_status;www.linuxtone.org""</span>
//특정 상황에 따라 조정하세요.location /nginx_status {<br>stub_status on;<br>access_log off;<br>allow 192.168.1.37;<br>deny all;<br>}
이 형식은 여러 가상 호스트의 연결 상태를 모니터링합니다.
# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`<br># wget http://forums.cacti.net/download.php?id=12676<br># tar xvfz cacti-nginx.tar.gz<br># cp cacti-nginx/get_nginx_socket_status.pl /data/cacti/scripts/<br># cp cacti-nginx/get_nginx_clients_status.pl /data/cacti/scripts/<br># chmod 755 /data/cacti/scripts/get_nginx*
초점 crond 서비스를 시작한 다음 http://219.32.205.13/nginx/html/을 통해 액세스하세요. 구성 과정은 간단합니다! 3. CACTI 템플릿 모니터링 NginxNginx_status 상태를 사용하여 그림을 그려 CACTI 모니터링 구현http_stub_status_module을 허용하도록 nginx 컴파일# vi /usr/local/nginx/conf/nginx.confCODE:location /nginx_status {stub_status on;access_log off ;192.168.1.37 허용;모두 거부;}
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*
탐지 플러그인 코드:# /data/cacti/scripts/get_nginx_clients_status.pl
http://192.168.1.37/nginx_status
선인장 관리 패널에서 CODE:
server {server {<br>listen 80;<br>server_name java.linuxtone.org<br>location / {<br>proxy_pass http://192.168.1.2:8080;<br>include /usr/local/nginx/conf/proxy.conf;<br>}<br>}
listen 80;server_name java.linuxtone.orglocation / {