nginx.conf 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 snailjob-server {
  27. server 127.0.0.1:8800;
  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. location /snail-job/ {
  82. proxy_set_header Host $http_host;
  83. proxy_set_header X-Real-IP $remote_addr;
  84. proxy_set_header REMOTE-HOST $remote_addr;
  85. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  86. proxy_pass http://snailjob-server/snail-job/;
  87. }
  88. error_page 500 502 503 504 /50x.html;
  89. location = /50x.html {
  90. root html;
  91. }
  92. }
  93. }