0.前期籌備
利用Debian情況。安裝Nginx(默認安裝),一個web項目,安裝tomcat(默認安裝)等。
1.一份Nginx.conf設置文件
# 界說Nginx運行的用戶 和 用戶組 假如對應處事器袒露在外面的話發起利用權限較小的用戶 防備被入侵
# user www www;
#Nginx歷程數, 發起配置為便是CPU總焦點數
worker_processes ;
#開啟全局錯誤日志范例
error_log /var/log/nginx/error.log info;
#歷程文件
pid /var/run/nginx.pid;
#一個Nginx歷程打開的最多文件描寫數目 發起與ulimit -n一致
#假如面臨高并發時 留意修改該值 ulimit -n 尚有部門系統參數 而并非這個單獨確定
worker_rlimit_nofile ;
events{
#利用epoll模子提高機能
use epoll;
#單個歷程最大毗連數
worker_connections ;
}
http{
#擴展名與文件范例映射表
include mime.types;
#默認范例
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout ;
types_hash_max_size ;
#日志
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
#gzip 壓縮傳輸
gzip on;
gzip_min_length 1k; #最小1K
gzip_buffers 64K;
gzip_http_version 1.1;
gzip_comp_level ;
gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
gzip_vary on;
#負載平衡組
#靜態處事器組
upstream static.zh-jieli.com {
server 127.0.0.1: weight=;
}
#動態處事器組
upstream zh-jieli.com {
server 127.0.0.1:;
#server 192.168.8.203:;
}
#設置署理參數
proxy_redirect off;
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 10m;
client_body_buffer_size 128k;
proxy_connect_timeout ;
proxy_send_timeout ;
proxy_read_timeout ;
proxy_buffer_size 4k;
proxy_buffers 32k;
proxy_busy_buffers_size 64k;
#緩存設置
proxy_cache_key '$host:$server_port$request_uri';
proxy_temp_file_write_size 64k;
proxy_temp_path /dev/shm/JieLiERP/proxy_temp_path;
proxy_cache_path /dev/shm/JieLiERP/proxy_cache_path levels=: keys_zone=cache_one:200m inactive=5d max_size=1g;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
server{
listen ;
server_name erp.zh-jieli.com;
location / {
index index; #默認主頁為 /index
#proxy_pass http://jieli;
}
location ~ .*.(js|css|ico|png|jpg|eot|svg|ttf|woff) {
proxy_cache cache_one;
proxy_cache_valid 5d;
proxy_cache_valid any 5d;
proxy_cache_key '$host:$server_port$request_uri';
add_header X-Cache '$upstream_cache_status from $host';
proxy_pass http://static.zh-jieli.com;
#所有靜態文件直接讀取硬盤
# root /var/lib/tomcat7/webapps/JieLiERP/WEB-INF ;
expires 30d; #緩存30天
}
#其他頁面反向署理到tomcat容器
location ~ .*$ {
index index;
proxy_pass http://zh-jieli.com;
}
}
server{
listen ;
server_name static;
location / {
}
location ~ .*.(js|css|ico|png|jpg|eot|svg|ttf|woff) {
#所有靜態文件直接讀取硬盤
root /var/lib/tomcat7/webapps/JieLiERP/WEB-INF ;
expires 30d; #緩存30天
}
}
}