nginx.production.conf 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. user www-data;
  2. worker_processes auto;
  3. pid /run/nginx.pid;
  4. error_log /var/log/nginx/error.log;
  5. include /etc/nginx/modules-enabled/*.conf;
  6. events {
  7. worker_connections 768;
  8. }
  9. http {
  10. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  11. '$status $body_bytes_sent "$http_referer" '
  12. '"$http_user_agent" "$http_x_forwarded_for"';
  13. access_log /var/log/nginx/access.log main;
  14. sendfile on;
  15. tcp_nopush on;
  16. tcp_nodelay on;
  17. keepalive_timeout 65;
  18. types_hash_max_size 4096;
  19. include /etc/nginx/mime.types;
  20. default_type application/octet-stream;
  21. include /etc/nginx/conf.d/*.conf;
  22. gzip on;
  23. gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/jpeg image/png image/gif;
  24. gzip_comp_level 6;
  25. gzip_min_length 1k;
  26. gzip_vary on;
  27. client_max_body_size 10M;
  28. server {
  29. listen 443 ssl;
  30. server_name cloudpure.cn;
  31. ssl_certificate /opt/key/www.cloudpure.cn.pem;
  32. ssl_certificate_key /opt/key/www.cloudpure.cn.key;
  33. return 301 https://www.cloudpure.cn$request_uri;
  34. }
  35. server {
  36. listen 443 ssl;
  37. server_name www.cloudpure.cn;
  38. ssl_certificate /opt/key/www.cloudpure.cn.pem;
  39. ssl_certificate_key /opt/key/www.cloudpure.cn.key;
  40. ssl_session_timeout 5m;
  41. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  42. ssl_protocols TLSv1.2 TLSv1.3;
  43. ssl_prefer_server_ciphers on;
  44. include /etc/nginx/default.d/*.conf;
  45. location /yunpubullet/ {
  46. proxy_pass http://127.0.0.1:8081/;
  47. proxy_set_header Host $host;
  48. proxy_set_header X-Real-IP $remote_addr;
  49. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  50. proxy_set_header X-Forwarded-Proto $scheme;
  51. }
  52. location = / {
  53. root /opt/web/dist;
  54. try_files /home/index.html =404;
  55. }
  56. location ~ ^/(home|product/(version-selection|intelligent-hr|intelligent-recruitment|intelligent-attendance|dingtalk-payroll|dingtalk-yida|teambition|intelligent-finance|intelligent-contract|intelligent-marketing)|ai|fde|digital-base|organization-digital|business-digital|solutions|cases|super-service|about|contact|privacy-policy|news)$ {
  57. return 301 $uri/$is_args$args;
  58. }
  59. location ~ ^/(home|product/(version-selection|intelligent-hr|intelligent-recruitment|intelligent-attendance|dingtalk-payroll|dingtalk-yida|teambition|intelligent-finance|intelligent-contract|intelligent-marketing)|ai|fde|digital-base|organization-digital|business-digital|solutions|cases|super-service|about|contact|privacy-policy|news)/?$ {
  60. root /opt/web/dist;
  61. try_files $uri $uri/ /$1/index.html =404;
  62. }
  63. location = /order-tai { return 301 /ai/; }
  64. location = /order-tai/ { return 301 /ai/; }
  65. # Keep pre-rendered article HTML when it exists. Fall back to the SPA so
  66. # newly published articles can load by slug before the next prerender.
  67. location = /news/test { return 404; }
  68. location = /news/test/ { return 404; }
  69. location ~ ^/news/article-fe2a72(?:[^/]*)?$ { return 404; }
  70. location ~ ^/news/article-fe2a72(?:[^/]*)?/$ { return 404; }
  71. location ~ ^/news/[^/]+$ {
  72. return 301 $uri/$is_args$args;
  73. }
  74. location ~ ^/news/[^/]+/$ {
  75. root /opt/web/dist;
  76. try_files $uri $uri/ /index.html;
  77. }
  78. location = /robots.txt {
  79. root /opt/web/dist;
  80. try_files $uri =404;
  81. }
  82. location = /sitemap.xml {
  83. root /opt/web/dist;
  84. try_files $uri =404;
  85. }
  86. location /static/ {
  87. root /opt/web/dist;
  88. try_files $uri =404;
  89. expires 30d;
  90. }
  91. # Normalize all other public page URLs without a trailing slash. API,
  92. # admin, assets, uploads, and file-like URLs are intentionally excluded.
  93. location ~ ^/(?!prod-api(?:/|$)|admin(?:/|$)|static(?:/|$)|profile(?:/|$)|yunpubullet(?:/|$)|robots\.txt$|sitemap\.xml$)(?:[^/]+/)*[^/.]+$ {
  94. return 301 $uri/$is_args$args;
  95. }
  96. location /profile/ {
  97. proxy_pass http://127.0.0.1:8080/profile/;
  98. }
  99. location = /admin {
  100. return 301 /admin/;
  101. }
  102. location = /admin/ {
  103. return 302 /admin/login;
  104. }
  105. location = /admin/index.html {
  106. alias /opt/admin/dist/index.html;
  107. }
  108. location ^~ /admin/static/ {
  109. alias /opt/admin/dist/static/;
  110. try_files $uri =404;
  111. }
  112. location ^~ /admin/ {
  113. rewrite ^ /admin/index.html last;
  114. }
  115. location /prod-api {
  116. proxy_set_header Host $http_host;
  117. proxy_set_header X-Real-IP $remote_addr;
  118. proxy_set_header REMOTE-HOST $remote_addr;
  119. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  120. proxy_pass http://127.0.0.1:8080;
  121. }
  122. location ~ ^/v3/api-docs/(.*) {
  123. proxy_pass http://localhost:8080/v3/api-docs/$1;
  124. }
  125. # Unknown website routes must not return the SPA shell.
  126. location / {
  127. root /opt/web/dist;
  128. try_files $uri $uri/ =404;
  129. }
  130. error_page 500 502 503 504 /50x.html;
  131. location = /50x.html {
  132. root html;
  133. }
  134. }
  135. server {
  136. listen 80;
  137. server_name cloudpure.cn www.cloudpure.cn;
  138. return 301 https://www.cloudpure.cn$request_uri;
  139. }
  140. include /etc/nginx/sites-enabled/*;
  141. }