nginx.conf 15 KB

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