This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

nginx/tr

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page Nginx and the translation is 83% complete.
Outdated translations are marked like this.

Warning: Display title "nginx/tr" overrides earlier display title "Nginx".

nginx ufak, güçlü ve yüksek performanslı bir web/ters proxy (reverse proxy) sunucu yazılımıdır. Apache ve lighttpd gibi popüler web sunucu yazılımları için iyi bir alternatiftir.

Kurulum

www-servers/nginx paketini kurmadan önce, kullanabildiği USE bayraklarına göz atalım.

Genişletilmiş USE bayrakları

Nginx uses modules to enhance its features. To simplify the maintenance of this modular approach, the nginx ebuild uses expanded USE (USE_EXPAND) flags to denote which modules should be installed.

  • HTTP related modules can be enabled through the NGINX_MODULES_HTTP variable
  • Mail related modules can be enabled through the NGINX_MODULES_MAIL variable
  • Third party modules can be enabled through the NGINX_ADD_MODULES variable

These variables need to be set in /etc/portage/make.conf. Their descriptions can be found in /usr/portage/profiles/desc/nginx_modules_http.desc and /usr/portage/profiles/desc/nginx_modules_mail.desc.

Örneğin fastcgi modülünü etkinleştirmek için:

FILE /etc/portage/make.conf
NGINX_MODULES_HTTP="fastcgi"

The above will overwrite the default value of NGINX_MODULES_HTTP and set it to fastcgi. To enable the fastcgi module without overwriting the default NGINX_MODULES_HTTP value, the following USE flag notation can be specified in /etc/portage/package.use:

FILE /etc/portage/package.use
www-servers/nginx NGINX_MODULES_HTTP: fastcgi

USE bayrakları

USE flags for www-servers/nginx Robust, small and high performance http and reverse proxy server

aio Enables file AIO support
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
http Enable HTTP core support
http-cache Enable HTTP cache support
http2 Enable HTTP2 module support
http3 Enable HTTP3 module support
ktls Enable Kernel TLS offload (kTLS)
libatomic Use libatomic instead of builtin atomic operations
pcre Add support for Perl Compatible Regular Expressions
pcre-jit Enable JIT for pcre
pcre2 Enable support for pcre2
rtmp NGINX-based Media Streaming Server
selinux  !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
ssl Enable HTTPS module for http. Enable SSL/TLS support for POP3/IMAP/SMTP for mail.
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
threads Add threads support for various packages. Usually pthreads
vim-syntax Pulls in related vim syntax scripts

Emerge

USE bayraklarıı ayarladıysanız, www-servers/nginx paketini kurun:

root #emerge --ask www-servers/nginx

Kurulumun onaylanması

The default nginx configuration defines a virtual server with the root directory set to /var/www/localhost/htdocs. However due to bug #449136, the nginx ebuild will only create the /var/www/localhost directory and without an index file. To have a working default configuration, create the /var/www/localhost/htdocs directory and simple index file:

root #mkdir /var/www/localhost/htdocs
root #echo 'Hello, world!' > /var/www/localhost/htdocs/index.html

nginx paketi, servisi durdurmak, başlatmak ve yeniden başlatmak için yardımcı olan bir servis betiği ile gelir. nginx servisini başlatmak için:

root #/etc/init.d/nginx start

To verify that nginx is properly running, point a web browser to the http://localhost address or use a command-line web tool like curl:

user $curl http://localhost

Yapılandırma

nginx yapılandırması /etc/nginx/nginx.conf dosyası üzerinde düzenlenir.

Tek site erişimi

Aşağıdaki örnek, (PHP gibi) dinamik özellikleri olmayan tek site yapılandırması içindir.

FILE /etc/nginx/nginx.confÖntanımlı Gentoo yapılandırması
user nginx nginx;
worker_processes 1;
  
error_log /var/log/nginx/error_log info;
  
events {
        worker_connections 1024;
        use epoll;
}
  
http {
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
  
        log_format main
                '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $bytes_sent '
                '"$http_referer" "$http_user_agent" '
                '"$gzip_ratio"';
  
        client_header_timeout 10m;
        client_body_timeout 10m;
        send_timeout 10m;
  
        connection_pool_size 256;
        client_header_buffer_size 1k;
        large_client_header_buffers 4 2k;
        request_pool_size 4k;
  
        gzip on;
        gzip_min_length 1100;
        gzip_buffers 4 8k;
        gzip_types text/plain;
  
        output_buffers 1 32k;
        postpone_output 1460;
  
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
  
        keepalive_timeout 75 20;
  
        ignore_invalid_headers on;
  
        index index.html;
  
        server {
                listen 127.0.0.1;
                server_name localhost;
  
                access_log /var/log/nginx/localhost.access_log main;
                error_log /var/log/nginx/localhost.error_log info;
  
                root /var/www/localhost/htdocs;
        }
}

Birden çok site erişimi

Birden fazla yapılandırma dosyasında daha kolay yönetim sağlamak için include yönergesi kullanılabilir:

FILE /etc/nginx/nginx.confBirden fazla site sunumu
user nginx nginx;
worker_processes 1;
   
error_log /var/log/nginx/error_log info;
  
events {
        worker_connections 1024;
        use epoll;
}
http {
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
  
        log_format main
                '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $bytes_sent '
                '"$http_referer" "$http_user_agent" '
                '"$gzip_ratio"';
  
        client_header_timeout 10m;
        client_body_timeout 10m;
        send_timeout 10m;
  
        connection_pool_size 256;
        client_header_buffer_size 1k;
        large_client_header_buffers 4 2k;
        request_pool_size 4k;
  
        gzip on;
        gzip_min_length 1100;
        gzip_buffers 4 8k;
        gzip_types text/plain;
  
        output_buffers 1 32k;
        postpone_output 1460;
  
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
  
        keepalive_timeout 75 20;
  
        ignore_invalid_headers on;
  
        index index.html;
 
        include /etc/nginx/conf.d/*.conf;
}
FILE /etc/nginx/conf.d/local.confÖrnek bir site
server {
        listen 127.0.0.1;
        server_name localhost;
  
        access_log /var/log/nginx/localhost.access_log main;
        error_log /var/log/nginx/localhost.error_log info;
  
        root /var/www/localhost/htdocs;
}
FILE /etc/nginx/conf.d/local-ssl.confÖrnek bir SSL destekli site
server {
    listen 443 ssl;
    server_name host.tld;
    ssl_certificate /etc/ssl/nginx/host.tld.pem;
    ssl_certificate_key /etc/ssl/nginx/host.tld.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:AES128:AES256:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK;
    ssl_dhparam /etc/ssl/nginx/host.tld.dh4096.pem;
    ssl_session_timeout 5m;
    ssl_session_cache shared:SSL:50m;
}

PHP desteği

PHP desteğini açmak için aşağıdaki satırları nginx yapılandırma dosyasına ekleyebilirsiniz. Bu örnekte nginx PHP ile iletişimini UNIX soketi üzerinden yapmakta.

FILE /etc/nginx/nginx.confPHP desteği örneği
...
http {
...
    server { 
    ...
            location ~ \.php$ {
                       # Olmayan dosyalari test edip 404 hatasi ver
                       # Bu satir olmazsa nginx gelen her .php ile biten istegi incelemeden php-fpm e gonderir
                       try_files $uri =404;
                       include /etc/nginx/fastcgi.conf;
                       fastcgi_pass unix:/run/php-fpm.socket;
           }
    }
}

To support this setup, PHP needs to be built with FastCGI Process Manager support (dev-lang/php), which is handled through the fpm USE flag:

root #echo "dev-lang/php fpm" >> /etc/portage/package.use

Ardından PHP'yi fpm USE bayrağıyla tekrar derleyelim:

root #emerge --ask dev-lang/php
Not
UNIX soket iletişimi önerilen yöntemdir

/etc/php/fpm-php5.5/php-fpm.conf dosyasını inceleyip aşağıdaki satırı ekleyin:

FILE /etc/php/fpm-php5.5/php-fpm.confPHP'yi UNIX soket desteğiyle çalıştırmak
listen = /run/php-fpm.socket
listen.owner = nginx

php-fpm'e ait php.ini dosyasında zaman dilimini ayarlayın. Bunun için ilgili zaman dilimini aşağıda <ZAMAN_DİLİMİ> ile belirtilen yere ekleyin:

FILE /etc/php/fpm-php5.5/php.iniphp.ini dosyasında zaman dilimi ayarı
date.timezone = <ZAMAN DİLİMİ>

Start the php-fpm daemon:

root #/etc/init.d/php-fpm start

Add php-fpm to the default runlevel:

root #rc-update add php-fpm default

Reload nginx with changed configuration:

root #/etc/init.d/nginx reload

IP adresiyle eirşim kısıtlaması

The next example shows how to allow access to a particular URL (in this case /nginx_status) only to:

  • certain hosts (e.g. 192.0.2.1 127.0.0.1)
  • and IP networks (e.g. 198.51.100.0/24)
FILE /etc/nginx/nginx.conf/nginx_status sayfası için IP adres kısıtlaması örneği
http {
    server { 
            location /nginx_status {
                     stub_status on;
                     allow 127.0.0.1/32;
                     allow 192.0.2.1/32;
                     allow 198.51.100.0/24;
                     deny all;
             }
     }
}

Basit yetkilendirme

nginx kullanıcı adı ve parola sorup yetkilendirme yapma desteğine de sahiptir:

FILE /etc/nginx/nginx.conf/ lokasyonu için kullanıcı adı - parola yetkilendirmesi
http {
    server { 
            location / {
                   auth_basic           "Authentication failed";
                   auth_basic_user_file conf/htpasswd;
             }
     }
}

htpasswd dosyası aşağıdaki şekilde oluşturulabilir:

user $openssl passwd

TLS desteği

Sadece TLS'in desteklenmesi ve güvensiz cipher desteğinin kullanılmaması önerilmekte.

FILE /etc/nginx/nginx.confEnabling TLS and disabling insecure ciphers
server {
    listen 443;
    server_name host.tld;
    ssl on;
    ssl_certificate /etc/ssl/nginx/host.tld.pem;
    ssl_certificate_key /etc/ssl/nginx/host.tld.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:AES128:AES256:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK;
    ssl_dhparam /etc/ssl/nginx/host.tld.dh4096.pem;
}

Kurulumda /etc/ssl/nginx/ konumuna sunucunun kendi imzaladığı sertifikalar yüklenmekte.

Daha fazla gizlilik

The diffie-hellman certificate can be created using openssl:

user $openssl dhparam -out dh4096.pem 4096

Üçüncü parti modüller

Üçüncü parti modülü indirip /usr/src dizinine koyun. Ardından elle derleyip, /etc/portage/make.conf dosyasına şu şekilde ekleyin:

FILE /etc/portage/make.conf3. parti modül ekleme
NGINX_ADD_MODULES="/usr/src/nginx_modülünün_ismi"

Üçüncü parti modül ile nginx'i tekrar derleyin:

root #emerge --ask www-servers/nginx

Kullanım

Servis kontrolü

OpenRC

Nginx'i başlatmak:

root #/etc/init.d/nginx start

Nginx'i durdur:

root #/etc/init.d/nginx stop

Nginx'i öntanımlı çalışma seviyesine ekle:

root #rc-update add nginx default

Nginx'i yeniden başlat:

root #/etc/init.d/nginx restart

Olası Problemler

Problem yaşarsanız aşağıdaki komutlar sebebini bulmanıza yardımcı olabilir.

Yapılandırmayı onaylama

nginx ayar dosyalarının belirgin bir hatası olmadığını kontrol etmek için:

root #/usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

By running nginx with the -t option, it will validate the configuration file without actually starting the nginx daemon.

İşlemlerin çalıştığına emin olun

Check if nginx processes are running:

user $ps aux | egrep 'nginx|PID'
  PID TTY      STAT   TIME COMMAND
26092 ?        Ss     0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
26093 ?        S      0:00 nginx: worker proces

Adres ve portların kullanımda olduğuna emin olun

nginx servisinin doğru portları dinlediğinden emin olun (HTTP için 80 ve HTTPS için 443 gibi):

root #netstat -tulpen | grep :80
tcp        0      0 127.0.0.1:80            0.0.0.0:*               LISTEN      0          12336835   -26092/nginx: master

Ayrıca bkz.

  • Apache - Popüler HTTP sunucusu
  • Lighttpd - Hızlı ve hafif bir web sunucu

Harici kaynaklar