bak.8.140.nginx.conf 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. server {
  2. listen 80 default_server;
  3. server_name _;
  4. # 启动Gzip Json模式 ######################################################
  5. gzip_http_version 1.0; # gzip支持http协议 proxy 必须用
  6. gzip on;
  7. gzip_vary on;
  8. gzip_proxied any;
  9. gzip_static on;
  10. gzip_comp_level 4;
  11. gzip_min_length 256;
  12. gzip_buffers 4 8k;
  13. gzip_types text/html text/plain application/javascript application/x-javascript text/css application/xml application/json;
  14. client_header_timeout 300;
  15. client_body_timeout 300;
  16. keepalive_timeout 300;
  17. proxy_connect_timeout 300;
  18. proxy_send_timeout 300;
  19. proxy_read_timeout 300;
  20. location /api {
  21. if ($request_method = 'OPTIONS') {
  22. add_header 'Access-Control-Allow-Origin' '*';
  23. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  24. #
  25. # Custom headers and headers various browsers *should* be OK with but aren't
  26. #
  27. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  28. #
  29. # Tell client that this pre-flight info is valid for 20 days
  30. #
  31. add_header 'Access-Control-Max-Age' 1728000;
  32. add_header 'Content-Type' 'text/plain; charset=utf-8';
  33. add_header 'Content-Length' 0;
  34. return 204;
  35. }
  36. if ($request_method = 'POST') {
  37. add_header 'Access-Control-Allow-Origin' '*' always;
  38. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  39. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Origin' always;
  40. add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  41. }
  42. if ($request_method = 'GET') {
  43. add_header 'Access-Control-Allow-Origin' '*' always;
  44. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  45. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Origin' always;
  46. add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  47. }
  48. rewrite ^/(.*)$ /$1 break;
  49. proxy_pass http://127.0.0.1:61336/api;
  50. }
  51. location /parse/{
  52. proxy_read_timeout 300;
  53. proxy_connect_timeout 300;
  54. proxy_set_header Host $http_host;
  55. proxy_set_header X-Real-IP $remote_addr;
  56. proxy_set_header X-Scheme $scheme;
  57. proxy_set_header X-Forwarded-Proto $scheme;
  58. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  59. proxy_pass http://127.0.0.1:61336/parse/;
  60. proxy_redirect off;
  61. }
  62. location /docs/ {
  63. proxy_read_timeout 300;
  64. proxy_connect_timeout 300;
  65. client_body_buffer_size 500m;
  66. client_max_body_size 1000m;
  67. rewrite ^/docs/(.*)$ /$1 break; # 去掉/docs/前缀
  68. proxy_pass http://localhost:3000; # 反向代理到本地的3000
  69. proxy_set_header Host $host;
  70. proxy_set_header X-Real-IP $remote_addr;
  71. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  72. proxy_set_header X-Forwarded-Proto $scheme;
  73. }
  74. root /var/www/edu-textbook/;
  75. location /{
  76. try_files $uri $uri/ /index.html?$query_string;
  77. }
  78. }