1,nginx的编译安装,次配置为官方给出的编译项次 http://nginx.org/en/linux_packages.html#stable
./configure \
--prefix=/etc/nginx \
--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.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-file-aio \
--with-http_spdy_module
2,编译安装完成后将main 配置文件与server 段配置文件分开
以下为分开后nginx.conf 的配置文件内容
user nginx;
worker_processes 4;
worker_rlimit_nofile 65000;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll;
multi_accept on;
worker_connections 1500;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
proxy_cache_path /var/cache/nginx/ keys_zone=cache_zone:10m;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
server_tokens off;
keepalive_timeout 65;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;
gzip on;
gzip_disable "msie6";
gzip_http_version 1.1;
gzip_vary on;
# gzip_static on;
gzip_proxied any;
gzip_min_length 1k;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
fastcgi_cache_path /tmp/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m;
fastcgi_cache_key "$request_method://$host$request_uri";
#uppstream loadbalance
upstream monitor {
server 10.185.40.20:8094 weight=1 max_fails=3 fail_timeout=20s;
# server 10.185.40.20:80 weight=3 max_fails=3 fail_timeout=20s;
}
include /etc/nginx/conf.d/*.conf;
}
相应的子配置文件如下将server 段单独进行配置;
vim /etc/nginx/conf.d/monitor.conf
server {
listen 80;
server_name localhost;
add_header X-Cache $upstream_cache_status;
fastcgi_cache TEST;
#
#charset koi8-r;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
access_log /var/log/nginx/map.access.log main;
proxy_pass http://monitor;
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
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 100m;
proxy_cache cache_zone;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 8k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location /status {
stub_status on;
access_log /var/log/nginx/status.access.log main;
auth_basic "NginxStatus";
auth_basic_user_file /etc/nginx/htpasswd;
}
location ~ \.php$ {
include fastcgi_params;
root /usr/share/nginx/html/php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
access_log /var/log/nginx/php.access.log main;
}
location ~* \.(jpg|gif|bmp|png)$ {
rewrite ^/manager/images/(.*\.(gif|jpg|png))$ /$1 last;
root /usr/share/nginx/html/photo;
access_log /var/log/nginx/photo.access.log main;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}