1. user nginx;
    2. worker_processes 2;
    3. error_log /var/log/nginx/error.log warn;
    4. pid /var/run/nginx.pid;
    5. worker_rlimit_nofile 40000;
    6. events {
    7. use epoll;
    8. worker_connections 8096;
    9. multi_accept on;
    10. }
    11. http {
    12. include mime.types;
    13. default_type application/octet-stream;
    14. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    15. '$status $body_bytes_sent "$http_referer" '
    16. '"$http_user_agent" "$http_x_forwarded_for"';
    17. access_log /var/log/nginx/access.log main;
    18. sendfile on;
    19. tcp_nopush on;
    20. tcp_nodelay on;
    21. keepalive_timeout 15;
    22. # gzip压缩功能设置
    23. gzip on;
    24. gzip_min_length 1k;
    25. gzip_buffers 4 32k;
    26. gzip_http_version 1.1;
    27. gzip_comp_level 6;
    28. gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
    29. gzip_vary on;
    30. upstream bootshiro {
    31. server 192.168.0.3:8085;
    32. #server 127.0.0.1:8081;
    33. }
    34. upstream angular {
    35. server 192.168.0.3:4200;
    36. }
    37. # 缓存配置
    38. proxy_cache_path /tmp/cache levels=1:2 keys_zone=my_cache:30m max_size=1G;
    39. server {
    40. listen 80;
    41. server_name http://tom.usthe.com;
    42. charset utf-8;
    43. #access_log logs/host.access.log main;
    44. location / {
    45. proxy_pass http://angular;
    46. proxy_redirect off;
    47. proxy_set_header Host $host:$server_port;
    48. proxy_buffering on;
    49. proxy_buffer_size 4k;
    50. proxy_buffers 4 32k;
    51. proxy_busy_buffers_size 64k;
    52. proxy_temp_file_write_size 64k;
    53. }
    54. location /api/ {
    55. #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
    56. proxy_pass http://bootshiro/;
    57. proxy_redirect off;
    58. proxy_set_header Host $host;
    59. proxy_set_header X-Real-IP $remote_addr;
    60. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    61. proxy_buffer_size 4k;
    62. proxy_buffers 4 32k;
    63. proxy_busy_buffers_size 64k;
    64. proxy_temp_file_write_size 64k;
    65. }
    66. #对静态资源缓存
    67. #location ~* \.(html|css|jpg|gif|ico|js)$ {
    68. # proxy_cache my_cache;
    69. # proxy_cache_key $host$uri$is_args$args;
    70. # proxy_cache_valid 200 301 302 30m;
    71. # expires 30m;
    72. # proxy_pass http://angular;
    73. #}
    74. }
    75. }