user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_rlimit_nofile 40000;
events {
use epoll;
worker_connections 8096;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
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;
tcp_nodelay on;
keepalive_timeout 15;
# gzip压缩功能设置
gzip on;
gzip_min_length 1k;
gzip_buffers 4 32k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
gzip_vary on;
upstream bootshiro {
server 192.168.0.3:8085;
#server 127.0.0.1:8081;
}
upstream angular {
server 192.168.0.3:4200;
}
# 缓存配置
proxy_cache_path /tmp/cache levels=1:2 keys_zone=my_cache:30m max_size=1G;
server {
listen 80;
server_name http://tom.usthe.com;
charset utf-8;
#access_log logs/host.access.log main;
location / {
proxy_pass http://angular;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location /api/ {
#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_pass http://bootshiro/;
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;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#对静态资源缓存
#location ~* \.(html|css|jpg|gif|ico|js)$ {
# proxy_cache my_cache;
# proxy_cache_key $host$uri$is_args$args;
# proxy_cache_valid 200 301 302 30m;
# expires 30m;
# proxy_pass http://angular;
#}
}
}