# Http sunucu kontrol modülü ile NGINX kurulum ve konfigürasyonu

[![](https://books.netdev.com.tr/uploads/images/gallery/2022-12/scaled-1680-/image-1669992880726.png)](https://books.netdev.com.tr/uploads/images/gallery/2022-12/image-1669992880726.png)

Bu yazıda, nginx i sunuculara aktif health check yollayacak şekilde derleyip kuruyoruz, 
sistem fedora36 rolling.

Config ve binary dosya /usr/local/nginx altında oluşacak dolayısı ile aşağıdaki bütün adımlar dosyların bu klasörde biriktiğini kabul eder.

kurulum sonunda aşağıdaki gibi bir "status page" de elde ederiz 

[![](https://books.netdev.com.tr/uploads/images/gallery/2022-12/scaled-1680-/image-1669992478618.png)](https://books.netdev.com.tr/uploads/images/gallery/2022-12/image-1669992478618.png)

## İşletim sisteminin eksiklerini yükle
eksik olan işletim sistemi paketlerini yüklüyoruz.

    sudo yum install epel-release
    sudo yum install git
    sudo yum  group install "C Development Tools and Libraries" "Development Tools"

## derleme için eksikleri kütüphaneleri yükle
Aşağıdaki kütüphaneler fedora36 da yüklü gelmiyor nginx için yüklü olmaları gerekiyor.

    sudo yum install pcre-devel
    sudo yum install zlib-devel
    sudo yum install  openssl-devel

## Uyumlu nginx ve http_health_chek modülünü klonla
Sadece aşağıdaki sürümü test ettim, daha yeni sürümler için çalışma yapmak gerekir.

    git clone https://github.com/nginx/nginx.git
    git clone https://github.com/zhouchangxun/ngx_healthcheck_module.git
    git checkout branches/stable-1.12


## Derleme
Derleme aşaması burada başlıyor

	git apply ../ngx_healthcheck_module/nginx_healthcheck_for_nginx_1.12+.patch
	./auto/configure --with-stream --add-module=../ngx_healthcheck_module/ --with-http_ssl_module
	sudo make && sudo make install
	cd /usr/local/nginx/

## systemd 
lokasyon olarak kayıt edilecek yer 
	
    /usr/lib/systemd/system/nginx.service
Unit file içeriği ;

    [Unit]
    Description=The NGINX HTTP and reverse proxy server
    After=syslog.target network-online.target remote-fs.target nss-lookup.target
    Wants=network-online.target

    [Service]
    Type=forking
    #PIDFile=/usr/local/nginx//nginx.pid
    GuessMainPID=1
    ExecStartPre=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -t
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    ExecReload=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -s reload
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    User=root

    [Install]
    WantedBy=multi-user.target


## Servisleri başlatalım 

    sudo systemctl daemon-reload
    sudo systemctl status nginx

## Standart nginx conf dosyası

lokasyonu : 
	
    /usr/local/nginx/conf/nginx.conf

içeriği ;

   	user  root root;
   	worker_processes  1;
   	error_log  logs/error.log  info;
   	#pid        logs/nginx.pid;

   	events {
       worker_connections  1024;
   	}

   	http {
       include /usr/local/nginx/conf/conf.d/*.conf;
   	}

   	stream {
       
       
   	}

## Load balance ile ilgili config
Lokasyonu :
	
    /usr/local/nginx/conf/conf.d

Dosyanın içeriği:

    Server {
    location /status {
                healthcheck_status json;
            }
    location / { 
              proxy_pass http://test.com;
            }   
    }
    upstream test.com {
            # simple round-robin
            server 7.20.5.104:8008;
            server 7.20.5.104:8006;

        check interval=3000 rise=2 fall=5 timeout=500 type=http;
        check_http_send "GET /active.html HTTP/1.1\r\nHost: 172.20.5.104\r\nAccept: */* \r\n\r\n";
        check_http_expect_alive http_2xx http_3xx;
    }



## Kaynak

[https://github.com/zhouchangxun/ngx_healthcheck_module#installation](https://github.com/zhouchangxun/ngx_healthcheck_module#installation)