nginx 관련 설정
accept_mutex
, , , on nginx , 。 on, event
worker_connections
worker process , , event
access_log path log_format
,log_format , http
log_format name string
,name ,string , http
sendfile on | off
sendfile() , ,
sendfile_max_chunk size
sendfile()
keepalive_timeout timeout
keepalive_requests number
, , , server location
listen IP:port | port
ip , sock
server_name name
, , , , server
:
server_name ~^www\.(.+)\.com$;
www.myserver.com nginx , , myserver , $1 , server , myserver , $1 myserver
name ip, ip
location
location = | ~ | ~* | ^~ uri
= uri
~
~*
^~
gzip
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;
gzip_disable "MSIE [1-6]\."; IE6
server gzip, server gzip off
rewrite
rewrite regex replacement [flag]
flag last、break、redirect、permanent
last: url , url server
break: url , url
redirect: url , 302,
permanent: url , 301,
rewrite_log on | off
, notice errorlog
server{
listen 80;
server_name www.myweb.name;
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip)${
valid_referers none blocked server_names *.myweb.name;
if ($invalid_referer){
rewrite ^/ http://www.myweb.com/images/forbidden.png;
}
}
}
nginx
#
yum -y install pcre-devel openssl-devel gcc*
useradd -r nginx
./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
make && make install
#
, , worker ,worker , , worker his, , , , , , ,
### worker
nginx master , / ,
nginx worker ,
#
set
$host
$remote_addr
$request_uri uri( location)
http://nginx.org/en/docs/http/ngx_http_core_module.html nginx http
###
location 4 ,
localtion, = , , ,
location [ = | ~ | ~* | ^~ ] uri {
= uri
~ ( )
~* ( )
^~
!~*: ,
!~: ,
}
### if condition
-d,!-d:
-e,!-e: ,
-f,!-f:
-x,!-x:
###
##rewrite replacement [flag]
flag
break , ( , )
last , rewrite
permanent 301 ,
redirect , , rewrite last ( 302 , )
if rewrite break
###
location /status {
stub_status on
}
access_log off; , ,
access_log syslog:server=address[,parameter=values] [format];
###
Active connections
server accepts handled requests
, , ( keepalive N )
,
Reading: 0 Writing: 1 Waiting: 3
reading .
writing
waiting keep-alive , active – (reading+writing), Nginx .
###
gzip on | off
gzip_buffers number size
gzip_comp_level 1
gzip_disable regex
gzip_http_version gzip http
gzip_min_length
gzip_proxied gzip
gzip_types test/plain application/xml image
http {
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
gzip_disable msie6
}
###
worker_processes 4; , auto
worker_rlimit_nofile 51200; worker ,
use , epool
expires
error_page
keepalive_timeout 65; 5
worker_connections 1024; worker
index
listen address[:port]
autoindex on; apache Indexes, ,
server_name ,
add_header Cache_Control private;
log_format
worker_cpu_affinity 0001 0010 0100 1000; worker cpu ( cpu mask, 1,2,3,4 )
worker_priority 0; NIS ,-20 20, 0, nginx cpu
###
auth_basic "authname" auth_basic
auth_basic_user_file "/path" ( htpasswd )
### nginx
ulimit -n vim /etc/security/limits.conf nginx nofile 51200
###
location /{
proxy_pass http://127.0.0.1/remote/;
proxy_set_header field value;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; header , , X-Real-IP (apache %h %{X-Real-IP}i)
}
###
upstream webservers { upstream server ,http
ip_hash iphash,
server IP backup; backup , ,down server
server IP weight=1;
server IP weight=1;
}
server {
location / {
proxy_pass http://webservers;
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header; ,
proxy_set_header X-Real-IP $remote_addr;
}
}
###
`server {
listen 80
server_name www.pro.com
location ~* \.(jpg|png|gif|jpeg|html|css|js) {
proxy_pass
}
}`
###
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;
, ,1:2 1 , , 2:2 , 1:2:3, ( ) (hash )
/data/nginx/cache/c/29/alkjasdflkjaslkdfjlkasdjf
inactive=time
max_size=size
proxy_cache zone|off , , upstream
Set-Cookie
Cache-Control containing "no-cache","no-store","private", or a "max-age" with a non-numberic or 0 value
Expires with a time in the past
X-Accel-Expires:0
proxy_cache_min_users: , 3
proxy_cache_use_stale: upstream nginx
proxy_cache_use_stale error | timeout | invalid_header | updating | http_500 | http_502 | http_504 | http_404 | off
proxy_cache_valid [code] time: , :proxy_cache_valid 200 302 10m;
proxy_cache_bypass string: ,nginx : :
proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;
http {
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
server {
location /{
proxy_pass http://www.test.com;
proxy_set_header Host \$host;
proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_valid 301 302 10m;
proxy_cache_valid any 1m;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
add_herder X-Via \$server_addr;
add_header X-Cache-Stauts $upstream_cache_status; // ipstream
}
}
}
###
worker
cache manager cache loader cache
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.