nginx.conf 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. server {
  2. server_name server.gdchat.cn;
  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/gdchat.cn/fullchain.pem; # managed by Certbot
  11. ssl_certificate_key /etc/letsencrypt/live/gdchat.cn/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. resolver 202.96.128.143 114.114.114.114 valid=300s;
  20. # 网络超时时间
  21. resolver_timeout 5s;
  22. # 启动Gzip Json模式 ######################################################
  23. gzip_http_version 1.0; # gzip支持http协议 proxy 必须用
  24. gzip on;
  25. gzip_vary on;
  26. gzip_proxied any;
  27. gzip_static on;
  28. gzip_comp_level 4;
  29. gzip_min_length 256;
  30. gzip_buffers 4 8k;
  31. gzip_types text/html text/plain application/javascript application/x-javascript text/css application/xml application/json;
  32. # Common Api For Nova Cloud To DIY RESTful services
  33. location /api {
  34. #
  35. # Wide-open CORS config for nginx
  36. #
  37. if ($request_method = 'OPTIONS') {
  38. add_header 'Access-Control-Allow-Origin' '*';
  39. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  40. #
  41. # Custom headers and headers various browsers *should* be OK with but aren't
  42. #
  43. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  44. #
  45. # Tell client that this pre-flight info is valid for 20 days
  46. #
  47. add_header 'Access-Control-Max-Age' 1728000;
  48. add_header 'Content-Type' 'text/plain; charset=utf-8';
  49. add_header 'Content-Length' 0;
  50. return 204;
  51. }
  52. if ($request_method = 'POST') {
  53. add_header 'Access-Control-Allow-Origin' '*' always;
  54. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  55. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
  56. add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  57. }
  58. if ($request_method = 'GET') {
  59. add_header 'Access-Control-Allow-Origin' '*' always;
  60. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  61. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
  62. add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  63. }
  64. rewrite ^/(.*)$ /$1 break;
  65. proxy_pass https://server.fmode.cn/api;
  66. }
  67. location /api/apig/face/match {
  68. #
  69. # Wide-open CORS config for nginx
  70. #
  71. if ($request_method = 'OPTIONS') {
  72. add_header 'Access-Control-Allow-Origin' '*';
  73. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  74. #
  75. # Custom headers and headers various browsers *should* be OK with but aren't
  76. #
  77. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Origin';
  78. #
  79. # Tell client that this pre-flight info is valid for 20 days
  80. #
  81. add_header 'Access-Control-Max-Age' 1728000;
  82. add_header 'Content-Type' 'text/plain; charset=utf-8';
  83. add_header 'Content-Length' 0;
  84. return 204;
  85. }
  86. if ($request_method = 'POST') {
  87. add_header 'Access-Control-Allow-Origin' '*' always;
  88. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  89. 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;
  90. add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  91. }
  92. if ($request_method = 'GET') {
  93. add_header 'Access-Control-Allow-Origin' '*' always;
  94. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
  95. 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;
  96. add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  97. }
  98. rewrite ^/(.*)$ /$1 break;
  99. proxy_pass https://server.fmode.cn/api/apig/face/match;
  100. }
  101. location /api/novaql {
  102. #
  103. # Wide-open CORS config for nginx
  104. #
  105. #add_header 'Access-Control-Allow-Origin' '*';
  106. add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, PATCH, POST, DELETE, OPTIONS';
  107. add_header 'Access-Control-Allow-Credentials' 'true';
  108. add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Headers, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization';
  109. rewrite ^/(.*)$ /$1 break;
  110. proxy_pass https://server.fmode.cn/api;
  111. }
  112. location /{
  113. #
  114. # Wide-open CORS config for nginx
  115. #
  116. # add_header 'Access-Control-Allow-Origin' '*';
  117. # add_header 'Access-Control-Allow-Credentials' 'true';
  118. #
  119. # set back end proxy
  120. #
  121. proxy_set_header Host $http_host;
  122. proxy_set_header X-Real-IP $remote_addr;
  123. proxy_set_header X-Scheme $scheme;
  124. proxy_set_header X-Forwarded-Proto $scheme;
  125. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  126. proxy_pass https://server.fmode.cn/;
  127. proxy_redirect off;
  128. }
  129. }