GitLab之Nginx漏洞修复方案

绝地灬酷狼 2022-10-17 01:55 295阅读 0赞
1、需求:nginx的resolver模块漏洞,涉及nginx版本0.60-1.20
2、解决方案:
  1. 替换gitlab自带的nginx,方案比较复杂,会出现较多问题
  2. 在gtilab外用nginx最新版再负载一层,这个方案不需要修改很多gitlab原有的配置,被暂时采用
3、具体实践:
  1. 下载最新版nginx(传送门->):nginx下载
  2. 安装nginx:

tar -xzvf nginx-1.21.0.tar.gz

cd nginx-1.21.0

./configure —prefix=/usr/local/nginx —with-stream —with-pcre —add-module=/app/nginx-module-vts —with-http_gzip_static_module —with-http_stub_status_module

make
make install

PS:如果缺少对应包模块下载即可,这里就不贴链接了

  1. 修改nginx.conf文件

    user nobody;

    worker_processes 1;

    error_log logs/error.log;

    error_log logs/error.log notice;

    error_log logs/error.log info;

    pid logs/nginx.pid;

  1. events {
  2. worker_connections 1024;
  3. }
  4. http {
  5. include mime.types;
  6. default_type application/octet-stream;
  7. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  8. # '$status $body_bytes_sent "$http_referer" '
  9. # '"$http_user_agent" "$http_x_forwarded_for"';
  10. #access_log logs/access.log main;
  11. sendfile on;
  12. #tcp_nopush on;
  13. #keepalive_timeout 0;
  14. keepalive_timeout 65;
  15. #gzip on;
  16. upstream gitlab {
  17. server 127.0.0.1:18080;
  18. }
  19. server {
  20. listen 80;
  21. server_name 10.10.10.10;
  22. #charset koi8-r;
  23. #access_log logs/host.access.log main;
  24. location / {
  25. client_max_body_size 1024m;
  26. proxy_redirect off;
  27. proxy_set_header Host $host:$server_port;
  28. proxy_set_header X-Real-IP $remote_addr;
  29. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  30. proxy_pass http://gitlab/;
  31. root html;
  32. index index.html index.htm;
  33. }
  34. #error_page 404 /404.html;
  35. # redirect server error pages to the static page /50x.html
  36. #
  37. error_page 500 502 503 504 /50x.html;
  38. location = /50x.html {
  39. root html;
  40. }
  41. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  42. #
  43. #location ~ \.php$ {
  44. # proxy_pass http://127.0.0.1;
  45. #}
  46. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  47. #
  48. #location ~ \.php$ {
  49. # root html;
  50. # fastcgi_pass 127.0.0.1:9000;
  51. # fastcgi_index index.php;
  52. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  53. # include fastcgi_params;
  54. #}
  55. # deny access to .htaccess files, if Apache's document root
  56. # concurs with nginx's one
  57. #
  58. #location ~ /\.ht {
  59. # deny all;
  60. #}
  61. }
  62. # another virtual host using mix of IP-, name-, and port-based configuration
  63. #
  64. #server {
  65. # listen 8000;
  66. # listen somename:8080;
  67. # server_name somename alias another.alias;
  68. # location / {
  69. # root html;
  70. # index index.html index.htm;
  71. # }
  72. #}
  73. # HTTPS server
  74. #
  75. #server {
  76. # listen 443 ssl;
  77. # server_name localhost;
  78. # ssl_certificate cert.pem;
  79. # ssl_certificate_key cert.key;
  80. # ssl_session_cache shared:SSL:1m;
  81. # ssl_session_timeout 5m;
  82. # ssl_ciphers HIGH:!aNULL:!MD5;
  83. # ssl_prefer_server_ciphers on;
  84. # location / {
  85. # root html;
  86. # index index.html index.htm;
  87. # }
  88. #}
  89. }
  1. 启动nginx服务:

    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

Nginx开机自启动看这里:

https://blog.csdn.net/lihailin9073/article/details/102535717

  1. 修改gitlab配置:

vim /etc/gitlab/gitlab.rb

  1. external_url 'http://10.10.10.10:18080'
  2. gitlab_rails['backup_path'] = "/gitlabdir/backups"
  3. gitlab_rails['backup_keep_time'] = 604800
  4. nginx['listen_addresses'] = ['127.0.0.1']
  5. nginx['client_max_body_size'] = '1024m'
  6. nginx['listen_port'] = 18080
  7. git_data_dirs({
  8. "default" => {
  9. "path" => "/gitlabdir/git-data"
  10. }
  11. })
  12. postgresql['data_dir'] = "/gitlabdir/gitlab/postgresql/data"
  13. postgresql['dir'] = "/gitlabdir/gitlab/postgresql"
  14. postgresql['home'] = "/gitlabdir/gitlab/postgresql"
  1. 更新下配置:

gitlab-ctl reconfigure

  1. 浏览器访问gitlab服务进行验证:http://10.10.10.10,成功即可!!

为了测试耗费了很长时间,踩了N多坑,有问题请留言,希望能帮到各位,不要恶语相向,谢谢!

发表评论

表情:
评论列表 (有 0 条评论,295人围观)

还没有评论,来说两句吧...

相关阅读