nginx-windows.conf 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #user root root;
  2. worker_processes 1; # 设置值和CPU核心数一致
  3. #error_log logs/error.log; # 日志位置和日志级别
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. pid logs/nginx.pid;
  7. # Specifies the value for maximum file descriptors that can be opened by this process.
  8. worker_rlimit_nofile 65535;
  9. events {
  10. worker_connections 1024;
  11. }
  12. http {
  13. include mime.types;
  14. default_type application/octet-stream;
  15. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  16. # '$status $body_bytes_sent "$http_referer" '
  17. # '"$http_user_agent" "$http_x_forwarded_for"';
  18. server_names_hash_bucket_size 128;
  19. client_header_buffer_size 32k;
  20. large_client_header_buffers 4 32k;
  21. client_max_body_size 8m;
  22. #access_log logs/access.log main;
  23. server_tokens off;
  24. sendfile on;
  25. tcp_nopush on;
  26. keepalive_timeout 60;
  27. tcp_nodelay on;
  28. gzip on;
  29. gzip_min_length 1k;
  30. gzip_buffers 4 16k;
  31. gzip_http_version 1.0;
  32. gzip_comp_level 2;
  33. gzip_types text/plain application/x-javascript text/css application/xml;
  34. gzip_vary on;
  35. # limit_zone crawler $binary_remote_addr 10m;
  36. upstream tomcat-patrol-app { # patrol-app
  37. server localhost:8898;
  38. }
  39. upstream tomcat-patrol-web { # patrol-web
  40. server localhost:8899;
  41. }
  42. # 下面是server虚拟主机的配置
  43. server {
  44. listen 80; # 监听端口
  45. server_name localhost; # 域名
  46. index index.html index.htm index.php;
  47. #access_log logs/host.access.log main;
  48. # 后端小程序接口网关
  49. location ^~ /patrol-app/ { # /patrol-app 开头代理到 tomcat-patrol-app
  50. proxy_set_header Host $host;
  51. proxy_set_header X-Real-IP $remote_addr;
  52. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  53. proxy_set_header X-Forwarded-Proto $scheme;
  54. proxy_pass http://tomcat-patrol-app/;
  55. }
  56. # 后端接口网关
  57. location ^~ /patrol-web/ { # /patrol-web 开头代理到 tomcat-patrol-web
  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_set_header X-Forwarded-Proto $scheme;
  62. proxy_pass http://tomcat-patrol-web/;
  63. }
  64. # 静态资源
  65. location ^~ /media {
  66. root E:/workspace-git/idea/spring-boot;
  67. }
  68. # 需要鉴权的资源
  69. location ^~ /mysql { #--with-http_auth_request_module
  70. auth_request /auth-proxy;
  71. add_header Access-Control-Allow-Origin * always;
  72. add_header Access-Control-Allow-Headers *;
  73. add_header Access-Control-Allow-Methods *;
  74. if ($request_method = 'OPTIONS') {
  75. return 204;
  76. }
  77. root E:/workspace-git/idea/spring-boot;
  78. }
  79. # 授权校验
  80. location /auth-proxy {
  81. internal;
  82. proxy_pass_request_body off; # 不转发body给鉴权
  83. proxy_set_header Content-Length ""; # 不转发body给鉴权
  84. proxy_pass "http://localhost:8899/v1/system/user/check/authorize"; # 鉴权地址
  85. }
  86. # VUE 网页
  87. location ^~ / { # /开头请求root,注意请求时带有/。
  88. root D:/web/;
  89. try_files $uri $uri/ /index.html; # 解决刷新后404问题
  90. }
  91. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
  92. expires 30d;
  93. }
  94. location ~ .*\.(js|css)?$ {
  95. expires 15d;
  96. }
  97. }
  98. }