Nginx 설치 및 상용 설정 문서
nginx-1.4.7.tar.gz
압축 풀기:
tar zxvf nginx-1.4.7.tar.gz
설치:
cd nginx-1.4.7
yum -y install pcre-devel openssl openssl-devel
yum install gcc
patch -p1 < /home/xinli/yaozhf/nginx_tcp_proxy_module/tcp.patch
./configure --prefix=/usr/local/nginx --add-module=/home/xinli/yaozhf/nginx_tcp_proxy_module
make
make install
프로필:
vi /usr/local/nginx/conf/nginx.conf
#
user www www;
# ( CPU , CPU, 8)
worker_processes 8;
# , :[ debug | info | notice | warn | error | crit ]
error_log /data1/logs/nginx_error.log crit;
# pid
pid /usr/local/webserver/nginx/nginx.pid;
#
worker_rlimit_nofile 51200;
events
{
# I/O ,Linux epoll ,FreeBSD kqueue
use epoll;
#
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
# , , , HTML Meta
#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 60;
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
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
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 www.yourdomain.com yourdomain.com;
index index.html index.htm index.php;
root /data0/htdocs;
#limit_conn crawler 20;
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;
}
}
시작:
\ # - c 설정 파일 의 경 로 를 지정 하 였 습 니 다.
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
정지:
\ # 주 프로 세 스 번호 찾기
ps -ef | grep nginx
\ # 여 유 롭 게 멈 춰 라
kill - QUIT nginx 메 인 프로 세 스 번호
\ # 빠 른 정지
kill - TERM nginx 주 프로 세 스 번호
kill - INT nginx 주 프로 세 스 번호
\ # 강제 정지
kill - 9 nginx 메 인 프로 세 스 번호
\ # 모든 nginx 강제 정지
pkill -9 nginx
killall nginx
nginx 메 인 프로 세 스 번호 사용 가능
` cat / usr / local / nginx / logs / nginx. pid ` 또는 $(cat / usr / local / nginx / logs / nginx. pid)
부 드 러 운 리 셋:
\ # 설정 파일 이 올 바른 지 판단 하기
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
\ # 부 드 럽 게 다시 시작
kill - UP nginx 메 인 프로 세 스 번호
alias 사용법:
\ # 일반적인 상황 에서 location / 에 루트 를 설정 하고 location / other 에 alias 를 설정 합 니 다.
location /mydir/ {
alias /var/myuser/mydir/;
# 자동 색인 활성화 / 닫 기 기본 값 은 off
autoindex on;
# 색인 파일 크기 의 단위 (B, KB, MB, GB) 를 기본 값 으로 on 으로 설정 합 니 다.
autoindex_exact_size off;
# 파일 시간 을 로 컬 시간 으로 표시 하려 면 기본 값 은 off 입 니 다.
autoindex_localtime on;
}
rewrite 사용법:
\ # 디 렉 터 리 가 존재 하지 않 습 니 다
if ( !-d $request_filename )
{
rewrite "/epg/([0-9]{8})(.*)" /mydir/current/ last;
}
http 부하 균형 용법:
\ # 전체 형식
http
{
# weight - 가중치, 높 을 수록 클 라 이언 트 연결 이 많 습 니 다. 기본 가중치 1
# max fails - 인자 fail timeout 이 지정 한 시간 동안 요청 에 실패 한 횟수 입 니 다. 기본 값 은 1 이 고 0 으로 설정 하여 이 검 사 를 닫 습 니 다.
# 다운 - 영구 오프라인 상태
# backup - 백업 서버 가 모두 다운 되 거나 바 쁠 때 만 사용 합 니 다.
upstream epg_server_pool {
server 192.168.3.227:80 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.3.228:80 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.3.229:80 down
server 192.168.3.243:80 backup
}
server {
listen 80;
server_name localhost;
location / {
#ip_hash
proxy_pass http://epg_server_pool
}
}
}
tcp 부하 균형 용법
\ # 전체 형식
tcp {
upstream auth_pool {
# the upstream server will be dispatched by ip_hash.
# ip_hash
server 192.168.3.242:5203;
server 192.168.3.243:5203;
# interval-the check request's interval time.
# rise-After rise_count check success, the server is marked up.
# fall-After rise_count check success, the server is marked up.
# timeout-the check request's timeout.
# type-the check protocol type.
check interval=3000 rise=2 fall=5 timeout=1000;
}
server {
listen 5203;
proxy_pass auth_pool;
# set the timeout value with clients. default: 60000 milliseconds
timeout 60000;
}
# set the timeout value of connection to backends.default: 60000 milliseconds
#proxy_connect_timeout 60000
# set the timeout value of reading from backends.default: 60000 milliseconds
#proxy_read_timeout 60000
# set the timeout value of sending to backends.default: 60000 milliseconds
#proxy_send_timeout 60000
}
Nginx 로그 스 크 립 트 자 르 기:
\ # 1 - 스 크 립 트 편집
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/logs/nginx.pid`
\ # 2 - crontab 설정
crontab -e
00 00 * * * /usr/local/nginx/sbin/cut_nginx_log.sh
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단! Certbot을 사용하여 웹 사이트를 SSL(HTTPS)화하는 방법초보자가 인프라 주위를 정돈하는 것은 매우 어렵습니다. 이번은 사이트를 간단하게 SSL화(HTTP에서 HTTPS통신)로 변경하는 방법을 소개합니다! 이번에는 소프트웨어 시스템 Nginx CentOS7 의 환경에서 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.