nginx.conf 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. user root;
  2. worker_processes auto;
  3. events {
  4. worker_connections 8192;
  5. use epoll;
  6. multi_accept on;
  7. }
  8. http {
  9. include mime.types;
  10. default_type application/octet-stream;
  11. charset utf-8;
  12. sendfile on;
  13. tcp_nopush on;
  14. tcp_nodelay on;
  15. keepalive_timeout 65;
  16. types_hash_max_size 2048;
  17. server_tokens off;
  18. # 全局 gzip
  19. gzip on;
  20. gzip_vary on;
  21. gzip_min_length 1024;
  22. gzip_proxied any;
  23. gzip_comp_level 6;
  24. gzip_types
  25. text/plain
  26. text/css
  27. text/js
  28. text/xml
  29. text/javascript
  30. application/javascript
  31. application/xml+rss
  32. application/json
  33. image/svg+xml;
  34. # =========================
  35. # ZKXW 管理端(测试环境 8112)
  36. # 静态目录: /root/zkxw/dist
  37. # API 反代: 47.99.164.66:8112
  38. # =========================
  39. server {
  40. listen 8112;
  41. listen [::]:8112;
  42. server_name 47.121.120.79 localhost 127.0.0.1;
  43. root /root/zkxw/dist;
  44. index index.html;
  45. client_max_body_size 500m;
  46. client_body_timeout 3600s;
  47. access_log /var/log/nginx/zkxw_admin_8112_access.log;
  48. error_log /var/log/nginx/zkxw_admin_8112_error.log;
  49. # 健康检查 / Swagger(须在 location / 之前;否则 /health 会走 SPA 返回 index.html)
  50. location = /health {
  51. proxy_pass http://47.99.164.66:8112/health;
  52. proxy_http_version 1.1;
  53. proxy_set_header Host $host;
  54. proxy_connect_timeout 10s;
  55. proxy_read_timeout 30s;
  56. }
  57. location ^~ /docs {
  58. proxy_pass http://47.99.164.66:8112;
  59. proxy_http_version 1.1;
  60. proxy_set_header Host $host;
  61. proxy_set_header X-Real-IP $remote_addr;
  62. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  63. proxy_set_header X-Forwarded-Proto $scheme;
  64. }
  65. location = /openapi.json {
  66. proxy_pass http://47.99.164.66:8112/openapi.json;
  67. proxy_http_version 1.1;
  68. proxy_set_header Host $host;
  69. }
  70. # 附件上传:大文件要等正文传完再落存储,不能跟普通接口共用 120s
  71. location ^~ /api/web/admin/attachment/upload {
  72. proxy_pass http://47.99.164.66:8112;
  73. proxy_http_version 1.1;
  74. proxy_set_header Host $host;
  75. proxy_set_header X-Real-IP $remote_addr;
  76. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  77. proxy_set_header X-Forwarded-Proto $scheme;
  78. proxy_request_buffering off;
  79. proxy_connect_timeout 30s;
  80. proxy_send_timeout 3600s;
  81. proxy_read_timeout 3600s;
  82. }
  83. # API -> 测试后端(47.99.164.66:8112)
  84. location ^~ /api/ {
  85. proxy_pass http://47.99.164.66:8112;
  86. proxy_http_version 1.1;
  87. proxy_set_header Host $host;
  88. proxy_set_header X-Real-IP $remote_addr;
  89. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  90. proxy_set_header X-Forwarded-Proto $scheme;
  91. proxy_connect_timeout 10s;
  92. proxy_send_timeout 120s;
  93. proxy_read_timeout 120s;
  94. }
  95. # MinIO 附件直链(bucket=zkxw;端口与后端 MINIO_ENDPOINT 映射一致,默认 20003)
  96. location ^~ /minio/zkxw/ {
  97. proxy_pass http://47.99.164.66:20003/zkxw/;
  98. proxy_http_version 1.1;
  99. proxy_set_header Host $http_host;
  100. proxy_set_header X-Real-IP $remote_addr;
  101. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  102. proxy_set_header X-Forwarded-Proto $scheme;
  103. proxy_request_buffering off;
  104. proxy_buffering off;
  105. proxy_read_timeout 600s;
  106. proxy_send_timeout 600s;
  107. proxy_connect_timeout 10s;
  108. add_header Access-Control-Allow-Origin * always;
  109. add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
  110. add_header Access-Control-Allow-Headers "DNT,User-Agent,Keep-Alive,Content-Type,Authorization,Range,If-Modified-Since,Cache-Control" always;
  111. if ($request_method = OPTIONS) {
  112. add_header Content-Length 0;
  113. add_header Content-Type text/plain;
  114. return 204;
  115. }
  116. }
  117. # SPA 路由(放最后,避免吞掉 /health、/api 等)
  118. location / {
  119. try_files $uri $uri/ /index.html;
  120. }
  121. # 静态资源缓存
  122. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  123. expires 30d;
  124. add_header Cache-Control "public, immutable" always;
  125. add_header X-Content-Type-Options nosniff always;
  126. access_log off;
  127. }
  128. # HTML 禁缓存,便于发版后立刻生效
  129. location ~* \.html$ {
  130. add_header Cache-Control "no-cache, no-store, must-revalidate" always;
  131. add_header Pragma "no-cache" always;
  132. add_header Expires "0" always;
  133. }
  134. # 禁止访问隐藏文件
  135. location ~ /\. {
  136. deny all;
  137. access_log off;
  138. log_not_found off;
  139. }
  140. }
  141. # =========================
  142. # SQXP Admin 静态服务(本机 3006)
  143. # =========================
  144. server {
  145. listen 3006;
  146. listen [::]:3006;
  147. server_name 127.0.0.1 localhost 47.121.120.79;
  148. root /root/sqxp-dist/dist;
  149. index index.html;
  150. access_log /var/log/nginx/sqxp_admin_3006_access.log;
  151. error_log /var/log/nginx/sqxp_admin_3006_error.log;
  152. # SPA 路由支持
  153. location / {
  154. try_files $uri $uri/ /index.html;
  155. }
  156. # 静态资源缓存
  157. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  158. expires 30d;
  159. add_header Cache-Control "public, immutable" always;
  160. add_header X-Content-Type-Options nosniff always;
  161. access_log off;
  162. }
  163. # HTML 禁缓存,便于发版后立刻生效
  164. location ~* \.html$ {
  165. add_header Cache-Control "no-cache, no-store, must-revalidate" always;
  166. add_header Pragma "no-cache" always;
  167. add_header Expires "0" always;
  168. }
  169. # 禁止访问隐藏文件
  170. location ~ /\. {
  171. deny all;
  172. access_log off;
  173. log_not_found off;
  174. }
  175. }
  176. # =========================
  177. # 主站:https://www.chengyantek.cn
  178. # =========================
  179. server {
  180. listen 443 ssl http2;
  181. listen [::]:443 ssl http2;
  182. server_name www.chengyantek.cn;
  183. ssl_certificate "/root/cert/www.chengyantek.cn.pem";
  184. ssl_certificate_key "/root/cert/www.chengyantek.cn.key";
  185. ssl_session_cache shared:SSL:10m;
  186. ssl_session_timeout 1h;
  187. ssl_protocols TLSv1.2 TLSv1.3;
  188. ssl_ciphers HIGH:!aNULL:!MD5;
  189. ssl_prefer_server_ciphers on;
  190. access_log /var/log/nginx/ahchengyan_access.log;
  191. error_log /var/log/nginx/ahchengyan_error.log;
  192. client_max_body_size 500m;
  193. client_body_timeout 3600s;
  194. # =========================
  195. # SQXP Admin 外部访问入口
  196. # =========================
  197. location ^~ /sqxp-admin/ {
  198. proxy_pass http://127.0.0.1:3006/;
  199. proxy_http_version 1.1;
  200. proxy_set_header Host $host;
  201. proxy_set_header X-Real-IP $remote_addr;
  202. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  203. proxy_set_header X-Forwarded-Proto $scheme;
  204. proxy_connect_timeout 10s;
  205. proxy_send_timeout 60s;
  206. proxy_read_timeout 60s;
  207. }
  208. # =========================
  209. # SQXP API 同域代理 -> 47.99.164.66:8000/api
  210. # 前端请求 /sqxp-api/web/... -> 后端 /api/web/...
  211. # =========================
  212. location ^~ /sqxp-api/ {
  213. proxy_pass http://47.99.164.66:8000/api/;
  214. proxy_http_version 1.1;
  215. proxy_set_header Host $host;
  216. proxy_set_header X-Real-IP $remote_addr;
  217. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  218. proxy_set_header X-Forwarded-Proto $scheme;
  219. proxy_connect_timeout 10s;
  220. proxy_send_timeout 60s;
  221. proxy_read_timeout 60s;
  222. }
  223. # 直接把 bucket 路径代理到 MinIO(bucket= sanqiang)
  224. location ^~ /sanqiang/ {
  225. proxy_pass http://127.0.0.1:20004/sanqiang/;
  226. proxy_http_version 1.1;
  227. proxy_set_header Host $http_host;
  228. proxy_set_header X-Real-IP $remote_addr;
  229. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  230. proxy_set_header X-Forwarded-Proto https;
  231. proxy_request_buffering off;
  232. proxy_buffering off;
  233. proxy_read_timeout 600s;
  234. proxy_send_timeout 600s;
  235. proxy_connect_timeout 10s;
  236. }
  237. # ===== MinIO 直链访问(新增,推荐)=====
  238. location ^~ /minio/ {
  239. proxy_pass http://127.0.0.1:20004/;
  240. proxy_http_version 1.1;
  241. proxy_set_header Host $http_host;
  242. proxy_set_header X-Real-IP $remote_addr;
  243. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  244. proxy_set_header X-Forwarded-Proto https;
  245. proxy_request_buffering off;
  246. proxy_buffering off;
  247. proxy_read_timeout 600s;
  248. proxy_send_timeout 600s;
  249. proxy_connect_timeout 10s;
  250. add_header Access-Control-Allow-Origin * always;
  251. add_header Access-Control-Allow-Methods "GET, PUT, POST, DELETE, HEAD, OPTIONS" always;
  252. add_header Access-Control-Allow-Headers "Authorization,Content-Type,Content-Length,Content-MD5,Date,ETag,Range,X-Amz-Date,X-Amz-Conte
  253. nt-Sha256,X-Amz-Security-Token,X-Amz-User-Agent" always;
  254. add_header Access-Control-Expose-Headers "ETag,Content-Length,Content-Range,Accept-Ranges,x-amz-request-id,x-amz-id-2" always;
  255. if ($request_method = OPTIONS) {
  256. add_header Content-Length 0;
  257. add_header Content-Type text/plain;
  258. return 204;
  259. }
  260. }
  261. # ===== 小程序静态资源 =====
  262. location ^~ /sqxp-static/ {
  263. alias /root/sqxp/;
  264. access_log off;
  265. if ($request_method = OPTIONS) {
  266. add_header Access-Control-Allow-Origin * always;
  267. add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
  268. add_header Access-Control-Allow-Headers "DNT,User-Agent,Keep-Alive,Content-Type,Authorization,Range,If-Modified-Since,Cache-Contr
  269. ol" always;
  270. add_header Access-Control-Max-Age 86400 always;
  271. add_header Content-Length 0;
  272. add_header Content-Type text/plain;
  273. return 204;
  274. }
  275. add_header Access-Control-Allow-Origin * always;
  276. add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
  277. add_header Access-Control-Allow-Headers "DNT,User-Agent,Keep-Alive,Content-Type,Authorization,Range,If-Modified-Since,Cache-Control"
  278. always;
  279. expires 30d;
  280. add_header Cache-Control "public";
  281. add_header Vary "Accept-Encoding";
  282. try_files $uri =404;
  283. }
  284. # favicon
  285. location = /favicon.ico {
  286. root /root/Lyrria/frontend/dist;
  287. access_log off;
  288. log_not_found off;
  289. expires 1y;
  290. add_header Cache-Control "public, immutable";
  291. }
  292. # robots
  293. location = /robots.txt {
  294. access_log off;
  295. log_not_found off;
  296. return 200 "User-agent: *\nDisallow:\n";
  297. }
  298. # WebSocket 代理
  299. location /ws {
  300. proxy_pass http://127.0.0.1:8766;
  301. proxy_http_version 1.1;
  302. proxy_set_header Upgrade $http_upgrade;
  303. proxy_set_header Connection "upgrade";
  304. proxy_set_header Host $host;
  305. proxy_set_header X-Real-IP $remote_addr;
  306. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  307. proxy_set_header X-Forwarded-Proto $scheme;
  308. proxy_read_timeout 3600s;
  309. proxy_send_timeout 3600s;
  310. proxy_connect_timeout 10s;
  311. }
  312. # API 代理(Lyrria)
  313. location ^~ /api/ {
  314. proxy_pass http://127.0.0.1:8766$request_uri;
  315. proxy_set_header Host $host;
  316. proxy_set_header X-Real-IP $remote_addr;
  317. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  318. proxy_set_header X-Forwarded-Proto $scheme;
  319. proxy_read_timeout 60s;
  320. proxy_send_timeout 60s;
  321. proxy_connect_timeout 10s;
  322. }
  323. # 主站静态资源缓存(Lyrria)
  324. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  325. root /root/Lyrria/frontend/dist;
  326. expires 30d;
  327. add_header Cache-Control "public, immutable" always;
  328. add_header X-Content-Type-Options nosniff always;
  329. }
  330. # SPA 路由支持(Lyrria)
  331. location / {
  332. root /root/Lyrria/frontend/dist;
  333. index index.html;
  334. try_files $uri $uri/ /index.html;
  335. add_header X-Frame-Options "SAMEORIGIN" always;
  336. add_header X-Content-Type-Options "nosniff" always;
  337. add_header X-XSS-Protection "1; mode=block" always;
  338. }
  339. # HTML 不缓存
  340. location ~* \.html$ {
  341. root /root/Lyrria/frontend/dist;
  342. add_header Cache-Control "no-cache, no-store, must-revalidate" always;
  343. add_header Pragma "no-cache" always;
  344. add_header Expires "0" always;
  345. try_files $uri =404;
  346. }
  347. # 禁止访问隐藏文件
  348. location ~ /\. {
  349. deny all;
  350. access_log off;
  351. log_not_found off;
  352. }
  353. location ~ ~$ {
  354. deny all;
  355. access_log off;
  356. log_not_found off;
  357. }
  358. }
  359. # 非www在443跳转到www
  360. server {
  361. listen 443 ssl http2;
  362. listen [::]:443 ssl http2;
  363. server_name chengyantek.cn;
  364. ssl_certificate "/root/cert/www.chengyantek.cn.pem";
  365. ssl_certificate_key "/root/cert/www.chengyantek.cn.key";
  366. return 301 https://www.chengyantek.cn$request_uri;
  367. }
  368. # =========================
  369. # 未来如果给 img.chengyantek.cn 单独申请好证书,再加这个 server
  370. # =========================
  371. # server {
  372. # listen 443 ssl http2;
  373. # listen [::]:443 ssl http2;
  374. # server_name img.chengyantek.cn;
  375. #
  376. # ssl_certificate "/root/.acme.sh/img.chengyantek.cn_ecc/fullchain.cer";
  377. # ssl_certificate_key "/root/.acme.sh/img.chengyantek.cn_ecc/img.chengyantek.cn.key";
  378. #
  379. # ssl_session_cache shared:SSL:10m;
  380. # ssl_session_timeout 1h;
  381. # ssl_protocols TLSv1.2 TLSv1.3;
  382. # ssl_ciphers HIGH:!aNULL:!MD5;
  383. # ssl_prefer_server_ciphers on;
  384. #
  385. # access_log /var/log/nginx/minio_img_access.log;
  386. # error_log /var/log/nginx/minio_img_error.log;
  387. #
  388. # client_max_body_size 100M;
  389. #
  390. # location / {
  391. # proxy_pass http://127.0.0.1:20004;
  392. # proxy_http_version 1.1;
  393. # proxy_set_header Host $http_host;
  394. # proxy_set_header X-Real-IP $remote_addr;
  395. # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  396. # proxy_set_header X-Forwarded-Proto https;
  397. # proxy_request_buffering off;
  398. # proxy_buffering off;
  399. # proxy_read_timeout 600s;
  400. # proxy_send_timeout 600s;
  401. # proxy_connect_timeout 10s;
  402. # }
  403. # }
  404. }