nginx-server.conf 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # server {
  2. # server_name _;
  3. # server_tokens off;
  4. # #large_client_header_buffers 4 32k;
  5. # client_max_body_size 50M;
  6. # charset utf-8;
  7. # index index.html;
  8. # # 启动SSL及证书匹配 ######################################################
  9. # listen 443 ssl default_server; # managed by Certbot
  10. # # ssl_certificate /etc/letsencrypt/live/edutextbook/fullchain.pem; # managed by Certbot
  11. # # ssl_certificate_key /etc/letsencrypt/live/edutextbook/privkey.pem; # managed by Certbot
  12. # # include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  13. # # ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  14. # # 启用OCSP stapling ######################################################
  15. # ssl_stapling on;
  16. # ssl_stapling_verify on;
  17. # # valid表示缓存5分钟
  18. # resolver 8.8.8.8 8.8.4.4 valid=300s;
  19. # # 网络超时时间
  20. # resolver_timeout 5s;
  21. # # 启动Gzip Json模式 ######################################################
  22. # gzip_http_version 1.0; # gzip支持http协议 proxy 必须用
  23. # gzip on;
  24. # gzip_vary on;
  25. # gzip_proxied any;
  26. # gzip_static on;
  27. # gzip_comp_level 4;
  28. # gzip_min_length 256;
  29. # gzip_buffers 4 8k;
  30. # gzip_types text/html text/plain application/javascript application/x-javascript text/css application/xml application/json;
  31. # location /api {
  32. # if ($request_method = 'OPTIONS') {
  33. # add_header 'Access-Control-Allow-Origin' '*';
  34. # add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  35. # #
  36. # # Custom headers and headers various browsers *should* be OK with but aren't
  37. # #
  38. # add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  39. # #
  40. # # Tell client that this pre-flight info is valid for 20 days
  41. # #
  42. # add_header 'Access-Control-Max-Age' 1728000;
  43. # add_header 'Content-Type' 'text/plain; charset=utf-8';
  44. # add_header 'Content-Length' 0;
  45. # return 204;
  46. # }
  47. # if ($request_method = 'POST') {
  48. # add_header 'Access-Control-Allow-Origin' '*' always;
  49. # add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  50. # 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;
  51. # add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  52. # }
  53. # if ($request_method = 'GET') {
  54. # add_header 'Access-Control-Allow-Origin' '*' always;
  55. # add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  56. # 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;
  57. # add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  58. # }
  59. # rewrite ^/(.*)$ /$1 break;
  60. # proxy_pass http://127.0.0.1:61337/api;
  61. # }
  62. # location /parse {
  63. # if ($request_method = 'OPTIONS') {
  64. # add_header 'Access-Control-Allow-Origin' '*';
  65. # add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  66. # #
  67. # # Custom headers and headers various browsers *should* be OK with but aren't
  68. # #
  69. # add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  70. # #
  71. # # Tell client that this pre-flight info is valid for 20 days
  72. # #
  73. # add_header 'Access-Control-Max-Age' 1728000;
  74. # add_header 'Content-Type' 'text/plain; charset=utf-8';
  75. # add_header 'Content-Length' 0;
  76. # return 204;
  77. # }
  78. # if ($request_method = 'POST') {
  79. # add_header 'Access-Control-Allow-Origin' '*' always;
  80. # add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  81. # 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;
  82. # add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  83. # }
  84. # if ($request_method = 'GET') {
  85. # add_header 'Access-Control-Allow-Origin' '*' always;
  86. # add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  87. # 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;
  88. # add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  89. # }
  90. # rewrite ^/(.*)$ /$1 break;
  91. # proxy_pass http://127.0.0.1:61337/parse;
  92. # }
  93. # location /{
  94. # proxy_set_header Host $http_host;
  95. # proxy_set_header X-Real-IP $remote_addr;
  96. # proxy_set_header X-Scheme $scheme;
  97. # proxy_set_header X-Forwarded-Proto $scheme;
  98. # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  99. # proxy_pass http://127.0.0.1:61337/;
  100. # proxy_redirect off;
  101. # }
  102. # }
  103. server {
  104. listen 80 default_server;
  105. server_name _;
  106. # 启动Gzip Json模式 ######################################################
  107. gzip_http_version 1.0; # gzip支持http协议 proxy 必须用
  108. gzip on;
  109. gzip_vary on;
  110. gzip_proxied any;
  111. gzip_static on;
  112. gzip_comp_level 4;
  113. gzip_min_length 256;
  114. gzip_buffers 4 8k;
  115. gzip_types text/html text/plain application/javascript application/x-javascript text/css application/xml application/json;
  116. location /api {
  117. if ($request_method = 'OPTIONS') {
  118. add_header 'Access-Control-Allow-Origin' '*';
  119. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  120. #
  121. # Custom headers and headers various browsers *should* be OK with but aren't
  122. #
  123. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  124. #
  125. # Tell client that this pre-flight info is valid for 20 days
  126. #
  127. add_header 'Access-Control-Max-Age' 1728000;
  128. add_header 'Content-Type' 'text/plain; charset=utf-8';
  129. add_header 'Content-Length' 0;
  130. return 204;
  131. }
  132. if ($request_method = 'POST') {
  133. add_header 'Access-Control-Allow-Origin' '*' always;
  134. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  135. 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;
  136. add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  137. }
  138. if ($request_method = 'GET') {
  139. add_header 'Access-Control-Allow-Origin' '*' always;
  140. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  141. 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;
  142. add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  143. }
  144. rewrite ^/(.*)$ /$1 break;
  145. proxy_pass http://127.0.0.1:61337/api;
  146. }
  147. location /parse/{
  148. proxy_set_header Host $http_host;
  149. proxy_set_header X-Real-IP $remote_addr;
  150. proxy_set_header X-Scheme $scheme;
  151. proxy_set_header X-Forwarded-Proto $scheme;
  152. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  153. proxy_pass http://127.0.0.1:61337/parse/;
  154. proxy_redirect off;
  155. }
  156. root /var/www/edu-textbook/;
  157. location /{
  158. try_files $uri $uri/ /index.html?$query_string;
  159. }
  160. }