nginx-server.conf 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. location /api {
  15. if ($request_method = 'OPTIONS') {
  16. add_header 'Access-Control-Allow-Origin' '*';
  17. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  18. #
  19. # Custom headers and headers various browsers *should* be OK with but aren't
  20. #
  21. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  22. #
  23. # Tell client that this pre-flight info is valid for 20 days
  24. #
  25. add_header 'Access-Control-Max-Age' 1728000;
  26. add_header 'Content-Type' 'text/plain; charset=utf-8';
  27. add_header 'Content-Length' 0;
  28. return 204;
  29. }
  30. if ($request_method = 'POST') {
  31. add_header 'Access-Control-Allow-Origin' '*' always;
  32. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  33. 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;
  34. add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  35. }
  36. if ($request_method = 'GET') {
  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. rewrite ^/(.*)$ /$1 break;
  43. proxy_pass http://127.0.0.1:61337/api;
  44. }
  45. location /parse/{
  46. proxy_set_header Host $http_host;
  47. proxy_set_header X-Real-IP $remote_addr;
  48. proxy_set_header X-Scheme $scheme;
  49. proxy_set_header X-Forwarded-Proto $scheme;
  50. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  51. proxy_pass http://127.0.0.1:61337/parse/;
  52. proxy_redirect off;
  53. }
  54. root /var/www/edu-textbook/;
  55. location /{
  56. try_files $uri $uri/ /index.html?$query_string;
  57. }
  58. }