nginx - 1.8.0 역방향 프 록 시 서버 구축 및 설정
CentOS 버 전 (컴 파일 설치 nginx 만)
yum install jemalloc jemalloc-devel -y
groupadd -r www
useradd -r -g www www -c "Web user" -d /dev/null -s /sbin/nologin
wget -c http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-ld-opt='-ljemalloc'
make
make install
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx
netstat -ano | grep \:80
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
Ubuntu 버 전 (nginx 만 컴 파일 하고 Ubuntu 를 설치 한 ww 사용 자 는 아래 설명 에 있 는 ww - data 를 사용 할 수 있 습 니 다)
apt-get install libjemalloc1 libjemalloc-dev
apt-get install libpcre3 libpcre3-dev
apt-get install openssl libssl1.0.0 libssl-dev
groupadd -r www
#www-data:x:33:
useradd -r -g www www -c "Web user" -d /dev/null -s /sbin/nologin
#www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
wget -c http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-ld-opt='-ljemalloc'
make
make install
/usr/local/nginx/sbin/nginx -t
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
ln -s /usr/local/nginx /etc/nginx
자신 이 사용 하 는 CentOS 버 전 (주로 설치 디 렉 터 리, pcre, zlib, openssl)
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxf nginx-1.8.0.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.10.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
mkdir /usr/local/chrisdata
tar zxf pcre2-10.10.tar.gz
tar zxf pcre-8.37.tar.gz
cd pcre-8.37
yum install gcc gcc-c++ -y
./configure --prefix=/usr/local/chrisdata/pcre
make
make install
cd ..
cd pcre2-10.10
./configure --prefix=/usr/local/chrisdata/pcre2
make
make install
cd ..
wget http://www.openssl.org/source/openssl-1.0.2a.tar.gz
tar zxf openssl-1.0.2a.tar.gz
wget http://zlib.net/zlib-1.2.8.tar.gz
tar zxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
ls
./configure --prefix=/usr/local/chrisdata/zlib
make
make install
cd ..
cd nginx-1.8.0
./configure --prefix=/usr/local/chrisdata/nginx --with-http_ssl_module --with-pcre=/root/pcre-8.37 --with-zlib=/root/zlib-1.2.8
./configure --prefix=/usr/local/chrisdata/nginx --with-http_ssl_module --with-openssl=/root/openssl-1.0.2a --with-pcre=/root/pcre-8.37 --with-zlib=/root/zlib-1.2.8 --with-http_stub_status_module
./configure --prefix=/usr/local/chrisdata/nginx --with-http_ssl_module --with-openssl=/root/openssl-1.0.2a --with-pcre=/root/pcre-8.37 --with-zlib=/root/zlib-1.2.8
make
make install
/usr/local/chrisdata/nginx/sbin/nginx -t
/usr/local/chrisdata/nginx/sbin/nginx
netstat -ano | grep \:80
ln -s /usr/local/chrisdata/nginx/sbin/nginx /usr/bin/nginx
mkdir /usr/local/nginx/conf/vhost
nginx 메 인 프로필 (lnmp 원 키 설치 패키지 (lnmp 1.2. tar. gz), 설명 제거)
user www www;
worker_processes auto;
error_log logs/error.log crit;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 51200;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
tcp_nopush on;
tcp_nodelay on;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
server_tokens off;
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include vhost/*.conf;
}
proxy upstream 로그 형식 설정 (요청 시간, 요청 길이, 응답 시간, 응답 상태, 응답 길이 등)
log_format backendtest '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'$bytes_sent '
'$request_length $request_time '
'$upstream_response_time $upstream_status $upstream_response_length $upstream_header_time $upstream_addr '
'"$http_user_agent" $http_x_forwarded_for';
upstream 설정
upstream backendtest {
server 192.168.1.102 weight=5;
#...
}
proxy server 설정 (location 뒤의 정규 사항 은 잘 연구 하 는 것 을 권장 합 니 다. stub status 를 사용 하려 면 '/' 이 어야 합 니 다. 일부 웹 프로그램 은 쓰기 문제 로 인해 상대 적 인 경로 문제 가 있 을 수 있 습 니 다. 예 를 들 어 css, js, 진일보 한 location 설정 을 고려 해 야 합 니 다)
server {
listen 8080;
server_name localhost;
#location ~ {
location / {
proxy_connect_timeout 300s;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 32k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Host $host;
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backendtest;
}
access_log /home/wwwlogs/vhost-8080-backendtest-access.log backendtest;
location /nginx_status {
stub_status on;
access_log off;
}
}
커 널 파라미터 최적화
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
fs.file-max = 808127
kernel.core_uses_pid = 1
kernel.hung_task_timeout_secs = 0
kernel.msgmax = 65536
kernel.msgmnb = 65536
kernel.sem = 250 32000 100 128
kernel.shmall = 4294967296
kernel.shmmax = 536870912
kernel.shmmax = 68719476736
kernel.shmmni = 4096
kernel.sysrq = 0
net.core.netdev_max_backlog = 262144
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.somaxconn = 262144
net.core.wmem_default = 8388608
net.core.wmem_max = 16777216
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.ip_forward = 0
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_sack = 1
net.ipv4.tcp_synack_retries = 5
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_syn_retries = 5
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_wmem = 4096 16384 4194304
파일 개수 최적화
vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
--end--