nginx.conf 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. worker_processes 1;
  2. error_log /var/log/nginx/error.log warn;
  3. pid /var/run/nginx.pid;
  4. events {
  5. worker_connections 1024;
  6. }
  7. http {
  8. include mime.types;
  9. default_type application/octet-stream;
  10. sendfile on;
  11. keepalive_timeout 65;
  12. # 限制body大小
  13. client_max_body_size 100m;
  14. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. '$status $body_bytes_sent "$http_referer" '
  16. '"$http_user_agent" "$http_x_forwarded_for"';
  17. access_log /var/log/nginx/access.log main;
  18. upstream server {
  19. ip_hash;
  20. server 127.0.0.1:8080;
  21. server 127.0.0.1:8081;
  22. }
  23. upstream monitor-admin {
  24. server 127.0.0.1:9090;
  25. }
  26. upstream powerjob-server {
  27. server 127.0.0.1:7700;
  28. }
  29. server {
  30. listen 80;
  31. server_name localhost;
  32. # https配置参考 start
  33. #listen 443 ssl;
  34. # 证书直接存放 /docker/nginx/cert/ 目录下即可 更改证书名称即可 无需更改证书路径
  35. #ssl on;
  36. #ssl_certificate /etc/nginx/cert/xxx.local.crt; # /etc/nginx/cert/ 为docker映射路径 不允许更改
  37. #ssl_certificate_key /etc/nginx/cert/xxx.local.key; # /etc/nginx/cert/ 为docker映射路径 不允许更改
  38. #ssl_session_timeout 5m;
  39. #ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  40. #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  41. #ssl_prefer_server_ciphers on;
  42. # https配置参考 end
  43. # 演示环境配置 拦截除 GET POST 之外的所有请求
  44. # if ($request_method !~* GET|POST) {
  45. # rewrite ^/(.*)$ /403;
  46. # }
  47. # location = /403 {
  48. # default_type application/json;
  49. # return 200 '{"msg":"演示模式,不允许操作","code":500}';
  50. # }
  51. # 限制外网访问内网 actuator 相关路径
  52. location ~ ^(/[^/]*)?/actuator(/.*)?$ {
  53. return 403;
  54. }
  55. location / {
  56. root /usr/share/nginx/html; # docker映射路径 不允许更改
  57. try_files $uri $uri/ /index.html;
  58. index index.html index.htm;
  59. }
  60. location /prod-api/ {
  61. proxy_set_header Host $http_host;
  62. proxy_set_header X-Real-IP $remote_addr;
  63. proxy_set_header REMOTE-HOST $remote_addr;
  64. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  65. # websocket参数
  66. proxy_http_version 1.1;
  67. proxy_set_header Upgrade $http_upgrade;
  68. proxy_set_header Connection "upgrade";
  69. proxy_pass http://server/;
  70. }
  71. # https 会拦截内链所有的 http 请求 造成功能无法使用
  72. # 解决方案1 将 admin 服务 也配置成 https
  73. # 解决方案2 将菜单配置为外链访问 走独立页面 http 访问
  74. location /admin/ {
  75. proxy_set_header Host $http_host;
  76. proxy_set_header X-Real-IP $remote_addr;
  77. proxy_set_header REMOTE-HOST $remote_addr;
  78. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  79. proxy_pass http://monitor-admin/admin/;
  80. }
  81. # https 会拦截内链所有的 http 请求 造成功能无法使用
  82. # 解决方案1 将 powerjob 服务 也配置成 https
  83. # 解决方案2 将菜单配置为外链访问 走独立页面 http 访问
  84. location /powerjob/ {
  85. proxy_set_header Host $http_host;
  86. proxy_set_header X-Real-IP $remote_addr;
  87. proxy_set_header REMOTE-HOST $remote_addr;
  88. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  89. proxy_pass http://powerjob-server/;
  90. }
  91. # 解决 powerjob 代理之后静态文件无法访问的问题 请勿修改乱动
  92. location ~ ^/(js|css|jpg|png|svg|woff|ttf|ico|img)/ {
  93. proxy_pass http://powerjob-server;
  94. }
  95. error_page 500 502 503 504 /50x.html;
  96. location = /50x.html {
  97. root html;
  98. }
  99. }
  100. }